Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Continue Statement Help

 
Weston SAE
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. }
 
Weston SAE
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much I had tried different combos using the % function but was unable to get the right combination. Until now. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic