Assignment #111 and Nesting Loops
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Nesting Loops
///File Name: NestingLoops.java
///Date Finished: 12/8/15
public class NestingLoops
{
public static void main( String[] args )
{
// the variable in the inner loop changes faster
for ( char c='A'; c <= 'E'; c++ )
{
for ( int n=1; n <= 3; n++ )
{
System.out.println( c + " " + n );
}
}//if the inner and outer loop are swapped then it prints a-e and 1, and then changes the number
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();
}//if changed to println then pit prints out the numbers in a column instead of the row
System.out.println("\n");
}
}
Picture of the output