Assignemnt #111 and Nesting Loops
Code
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Nesting Loops
/// File Name: NestingLoops.java
/// Date Finished: 5/4/2016
public class NestingLoops
{
public static void main( String[] args )
{
// this is #1 - I'll call it "CN"
for ( int n = 1; n <= 3; n++ )
{
for ( char c='A'; c <= 'E'; c++ )
{
System.out.println( c + " " + n );
}
}
System.out.println("\n");
// this is #2 - I'll call it "AB"
for ( int a=1; a <= 3; a++ )
{
for ( int b=1; b <= 3; b++ )
{
System.out.print( a + "-" + b + " " );
}
System.out.println();
}
System.out.println("\n");
//1. The variable with the inner loop (n) changes faster.
//2. Now (c) changes faster than (n).
//3. It makes each new loop on a seperate line.
//4. Now it displays a new line for each (A) loop.
}
}
Picture of the output