wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes what's wrong with the for-each Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what Watch "what New topic
Author

what's wrong with the for-each

Bin Qian
Greenhorn

Joined: Sep 13, 2006
Posts: 18
Hello everyone:
here is the code



the program calculates the average of sumOfNumber(a variable in the program) integers, and the sumOfNumber is enterd by users also the number;
when i use comment(1) it's ok,but it doesn't work when i use commnet(2), why???
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

By "doesn't work" do you mean doesn't compile? If so, check the version of Java you are using; the for : each syntax is only available from v5.0 up.

If by "doesn't work" you mean something else, can you lease explain what that is (by describing the behaviour and/or posting any stack trace you have)?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
The foreach-loop (as in //(2)) is equivalent to

There is no "reassignment" like "number[i]=nb".
Bin Qian
Greenhorn

Joined: Sep 13, 2006
Posts: 18
ok !thank you everyone espatically Anton Uwe!
i see now!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's wrong with the for-each
 
Similar Threads
To find the Medium
Input Validation Help
sum up numbers
Using percent Modulus to calculate total number of even numbers from user input
TestScores