Topic 6 Nested For Loops
Topic 6 Nested For Loops
8Output?
Output?
8Do you really need a nested
for loop in this case?
CS305j Introduction to Computing Nested For Loops 4
Nested for loop exercise
8What is the output of the following nested for
loop?
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
8 Output:
*
**
***
****
*****
******
8Output?
Output?
....1
...22
..333
.4444
55555
– Examples:
public static final int DAYS_IN_WEEK = 7;
public static final double INTEREST
INTEREST_RATE
RATE = 3
3.5;
5;
public static final int SSN = 658234569;
System.out.print("|");
S t t i t("|")
for (int i = 1; i <= 2 * FIGURE_WIDTH; i++) {
System.out.print(" ");
}
System.out.println("|");
drawPlusLine();
}
CS305j Introduction to Computing Nested For Loops 21