This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Continue Statement Help 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 "Continue Statement Help" Watch "Continue Statement Help" New topic
Author

Continue Statement Help

Weston SAE
Greenhorn

Joined: Feb 13, 2003
Posts: 2
I am very very new at this java thing, and I am trying to count to 10 and display only the odd integer values using a continue statement. I can get the code to skip the integer I specify in line 5 but how do I do multiple integers (skip 2,4,6,8,10)?
1. public class App {
2. public static void (String[] args){
3.
4. for (int x = 1; x <= 10; x++) {
5. if (x == 2)
6. continue;
7. else
8. System.out.print(" " + x);
9. }
10. }
11. }
Any help would be great.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
try this:
1. public class App {
2. public static void (String[] args){
3.
4. for (int x = 1; x <= 10; x++) {
5. if (x%2 == 0)
6. continue;
7. else
8. System.out.print(" " + x);
9. }
10. }
11. }


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Weston SAE
Greenhorn

Joined: Feb 13, 2003
Posts: 2
Thank you so much I had tried different combos using the % function but was unable to get the right combination. Until now. Thanks again.
 
 
subject: Continue Statement Help
 
Similar Threads
Doubt in K&B concerning topic :Operators
switch doubt..
how many objects are eligible for Garbage collection
aravind sethurathnam
Display an array in a swing type box