• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Continue Statement Help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic