Currently I am studying for my Java test. Whist studying I\'ve come across a small problem.
In this for loop:
for ( int i=1; i <= 3 ; i++ ) {
Let's look at what this would look like if we changed from loops to repeated code. First the outer loop:
for (int j=1; j <= 3 ; j++ ) {
System.out.println( 1 + " " + j );
}
for (int j=1; j <= 3 ; j++ ) {
System.out.println( 2 + " " + j );
}
for (int j=1; j <= 3 ; j++ ) {
System.out.println( 3 + " " + j );
}
Now the inner loop:
// First loop
System.out.println( 1 + " " + 1 );
System.out.println( 1 + " " + 2 );
System.out.println( 1 + " " + 3 );
// Second loop
System.out.println( 2 + " " + 1 );
System.out.println( 2 + " " + 2 );
System.out.println( 2 + " " + 3 );
// Third loop
System.out.println( 3 + " " + 1 );
System.out.println( 3 + " " + 2 );
System.out.println( 3 + " " + 3 );
Does it make sense now?