Assignemnt #111 and Nesting Loops
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Nesting Loops
///File Name: NestingLoops
///Date Finshed: 3/21/16
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 );
}
}
//The "n" or inner loop variable changes faster.
//The output changes with letter changing faster than the numbers.
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");
//The output changes with the a-b to be on seperate lines, not on the same line.
//The output changes with the a-b to be in a three by three grid.
}
}
Picture of the output