Java allows two or more variables to control a for loop.
public class Main {
public static void main(String args[]) {
for (int a = 1, b = 4; a < b; a++, b--) {
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
}
The program generates the following output:
a = 1
b = 4
a = 2
b = 3
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |