Java tutorial 7, Nested For Loops, To Generate Patterns, Part 2.
The output as stated below, only need to change the condition for 2nd for loop .
//Java Nested Loops
/* Program to generate the following output
Use the same program as previous tutorial
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
*/
public class NestedLoop5 {
public static void main(String[] args){
// I use two nested for loop to generate the pattern
// to generate 5 rows
for(int i = 1; i <= 5 ; i++){
//change here
//
for(int j = 1 ; j <= 5 - i + 1 ; j++){
System.out.print(j + " ");
}
System.out.println(" ");
}
}
}
No comments:
Post a Comment