Assignemnt #111 Nesting Loops
Code
public class NestingLoops
{
public static void main( String[] args )
{
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. The inner loops variable changes 3 times per 1 time the outer loop changes. Thus, the variable controlled by the inner loop changes faster.
2. For each number, all the letters from a -> e will be printed with a number after.
3. This makes it so after each "1-1" individual thing it will go to the next line.
4. This makes it so after each complete set beginning with the same number, it will go to the next line.
*/
Picture of the output