111 Nesting Loops
Code
//Tyler Hart
//period 5
//Nesting Loops.java
//NestingLoops
//11/10/2015
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 );
}
}
/*
1.n changes faster
2.now c changes faster
3.it makes the #-# have their own line every time
4.it print lines only when the outer loop repeats
*/
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");
}
}
Picture of the output