Assignment # 111 and Nesting
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: Nesting
/// File Name: Nesting.java
/// Date: 5/5/16
///1. The variable (n) controlled by the inner loop changes faster
///2. It's changed because c changes faster than n because n doesn't change value until c has looped from A through E
///3. The output changes because now each time loop b repeats the output is printed on a new line
///4. The output changes because each time the a loop reapeats its printed on a new line
public class Nesting
{
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");
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");
}
}
Picture of the output