• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

While loop help

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have written a while loop, and I would like your  help to make it run.

Thanks.

 
Sheriff
Posts: 17783
306
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you describe your problem in more detail? What are you expecting to happen? What is happening instead?
 
Junilu Lacar
Sheriff
Posts: 17783
306
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable mean is declared inside the while loop so it's only visible there. Outside the while loop, mean does not exist.

Check your loop condition. You have an off-by-one error in logic.
 
Marshal
Posts: 82459
594
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't write System.exit(). Least of all where you put it; your program is about to terminate normally anyway.
Lat's have some guesses about what's gone wrong. Is your loop running a different number of times from what you expected, as Junilu has hinted? Are you entering small numbers and getting an average of 0?
 
John D.West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Don't write System.exit(). Least of all where you put it; your program is about to terminate normally anyway...



The loop didn't work. I changed it as Junilu advised and it now works.
 
John D.West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:
...Check your loop condition. You have an off-by-one error in logic....



Thanks it now works.
 
John D.West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just one more question . Why does Netbeans report this error ?

NewClass.java:23: error: reached end of file while parsing
   }
1 error
 
Junilu Lacar
Sheriff
Posts: 17783
306
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like you have a stray .java file. You probably just want to find it and delete it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic