Program #111

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Nesting Loops
    /// File Name: Nesting.java
    /// Date Finished: 3/8/2016 public class Nesting

        public class Nesting
        {
        	public static void main( String[] args )
        	{
        		// This is #1 ("CN")
        			for ( int n=1; n <= 3; n++ )
        			{
                       for ( char c='A'; c <= 'E'; c++ )
                       {
        		 
        				System.out.println( c + " " + n );
                       }
        			}
                //For-loop n changes faster than the other variables.
                //The output order changes when one reverses the loops.
        
        		System.out.println("\n");
        
        		// This is #2 ("AB")
        		for ( int a=1; a <= 3; a++ )
        		{
        			for ( int b=1; b <= 3; b++ )
        			{
        				System.out.print( a + "-" + b + " " );
        			}
                    System.out.println();
                    //Because it is changed to println, each time it loops it moves to the next line.
                    //When you add a Sytem.out.println(), the program will go to the next run once the inner loop finishe.
        		}
        
        		System.out.println("\n");
        
        	}
        }

             
    

Picture of the output

Assignment 111