Assignment #111 Nesting Loops

Code

    Name: Iaroslav Titov
    Period: 7
    Project Name: NestingLoops
    File Name: NestingLoops.java
    Date: 1/12/2015
    
import java.util.Scanner;
import java.util.InputMismatchException;

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. In CN loop variable n changes faster, b/c it changes three times for rach change of c, b/c it is inside.
// 2. Now c changes more frequently then n, b/c now char loop is inside.
// 3. It is now displayed 2 numbers (1 AB pair) on each line.
// 4. Now it is displayed 6 numbers (3 AB pairs) per line, b/c .println() only performs 1 time for 3 changes of B (1 change of A).

    

Picture of the output

Assignment 108