Campbell Ritchie wrote:Challenge: write code to accumulate ints into an array without using a loop. There is a straightforward and elegant way to do it. You can count elements in the array as you go, but that is awkward and it might not be necessary: you can use the length field of the array instead.
Paul Clapham wrote:Do you mean, how can you display the loop variable "count" after the loop finishes? You can't, not given the code you posted. But when the loop finishes you know that its value is equal to the value of "loop". You could display that.
Or you could just declare the variable outside the loop.
Carey Brown wrote:Your class name 'main' should begin with an upper case letter. Variables should be declared separately. Use Scanner instead of BufferedReader, then you can use nextInt() instead of parseInt().
Carey Brown wrote:
yan cle wrote:
Carey Brown wrote:You are not tracking which letters you've already counted.
Hint: sort 'c'
But still follow Campbell's advice and work it out with pencil and paper first.
sorry im confuse, im just new to java, and my teacher did'nt taught us about encrpytion, thanks for your answer.
I was referring to your character counts, not the encryption.
Paul Clapham wrote:
salvin francis wrote:I see a small flaw in the encryption algorithm itself.
True... but the requirements (at least those posted here) don't say anything about decryption. So that isn't a problem.
Campbell Ritchie wrote:Welcome to the Ranch
![]()
Afraid you have put the cart before the horse. Write down the algorithm you are going to use for one part of the assignment. You shouldn't write any code before you have decided what you are going to do. Don't try to do the whole assignment all at once.
Carey Brown wrote:You are not tracking which letters you've already counted.
Hint: sort 'c'
But still follow Campbell's advice and work it out with pencil and paper first.
salvin francis wrote:I see a small flaw in the encryption algorithm itself. If you subtract 1 from vowels and add one to consonants, how will the decryption algorithm work ?
e.g Both "c" and "e" would result in "d".