For loops #111 (The faster we go...)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name: Nesting Loops
/// File Name:NestingLoops.java
/// Date Finished: 4/28/2016
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 );
}
}
// Before adjusting the code, the variable 'N' changes faster
// After adjusting the code, the Character changed before the numbers did
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();
// Adding the statement above makes it so that the set of numbers both line up and stack on each other
}
// When you change the print() statement to be a println() each set of numbers will appear on top of each other rather than next to each other
System.out.println("\n");
}
}
Picture(s) of the output