Created
November 9, 2015 14:02
-
-
Save OOPUniversity/5eafc83df9d9ef93aebe to your computer and use it in GitHub Desktop.
Demonstrates simple for loops, including a 'nested' loop
which generates a multiplication table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main.java.com.oopuniversity.basics.loops; | |
/** | |
* Created by OOPUniversity on 11/15/2014. | |
*/ | |
public class For { | |
public static void main(String [] args) { | |
for1(); | |
for2(); | |
for3(); | |
} | |
public static void for1() { | |
System.out.println("for1"); | |
for (int runCount = 0 ; runCount < 5 ; runCount ++ ) { | |
System.out.println("I am in a loop."); | |
} | |
} | |
public static void for2() { | |
System.out.println("for2"); | |
for ( int i = 0 ; i < 10 ; i++ ) { | |
System.out.println("Loop iteration " + i ); | |
} | |
} | |
/** | |
* Demonstrates 'nested' for loops | |
*/ | |
public static void for3() { | |
System.out.println("for3"); | |
for ( int i = 0 ; i < 5 ; i++ ) { | |
for ( int j = 0 ; j < 5 ; j++ ) { | |
int product = i * j ; | |
System.out.println (i + " X " + j + " = " + product ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment