Assignment #111 and Nesting Loops
Code
///Name: Ali Kurland
/// Period: 6
/// Program Name: Nesting Loops
/// File Name: NestingLoops.java
/// Date Finished: 1/28/2016
/// 1. The variable controlled by the inner loop (n) changes faster.
/// 2. The output changes in that c now changes faster than n because n does not change value until c has looped through all possible values (A through E).
/// 3. The output changes in that each time b loop repeats, the output is printed on a seperate line.
/// 4. The output changes in that each time the a loop reapeats (three iterations of AB), the output is printed on a new line.
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");
}
}
Picture of the output