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.
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: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().
it should be just bufferedreader
yan cle
Greenhorn
Posts: 15
posted 5 days ago
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.
yes, if i put like this
Number of Loop: 5
INDEX [0]: 1
INDEX [1]: 2
INDEX [2]: 3
INDEX [3]: 3
INDEX [4]: 3
this index from 0-4 should display or declare them outside the loop how can i do that? so i can use them if i put if or compare them to the new input
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.
yan cle
Greenhorn
Posts: 15
posted 5 days ago
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.
its already done,i did my calculation earlier and i made it, i may closed this thread aha..
Campbell Ritchie
Marshal
Posts: 71629
312
posted 5 days ago
You can't keep me quiet that easily As an alternative, you can test a regex in line 3.
[edit] Somebody has pointed out a spelling mistake in my code. I am leaving finding it as an “exercise for the reader”.
Eat that pie! EAT IT! Now read this tiny ad. READ IT!