Assignemnt #111

Code



    /// Name: Daniel Nguyen
    /// Period: 6
    /// Project Name: NestingLoops
    /// File Name: NestingLoops.java
    /// Date: 3/11/2015

// 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).

public class NestingLoops
{
	public static void main( String[] args )
	{
		// this is #1 - I'll call it "CN"
		for ( char c='A'; c <= 'E'; c++ )
		{
			for ( int n=1; n <= 3; n++ )
			{
				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 + " " );
			}
			// * You will add a line of code here.
		}

		System.out.println("\n");

	}
}







    

Picture of the output

Assignment 3
BACK HOME NEXT