File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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