• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

outside the loop

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i declare my input on the loop outside the loop and im using array, thanks for who's answering this.


how can i display it outside the input[count] outside the loop.
 
Saloon Keeper
Posts: 7618
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 26300
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7618
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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”.
 
You didn't tell me he was so big. Unlike this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic