ICSE Class 10 Computer Applications
Question 3 of 22
Nested for loops — Question 3
Back to all questions 3
Question Question 2(ii)
Write a program in Java to display the following patterns.
1 * * * *
* 2 * * *
* * 3 * *
* * * 4 *
* * * * 5
public class KboatPattern
{
public static void main(String args[]) {
char ch = '*';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5 ; j++) {
if(i == j)
System.out.print(i + " ");
else
System.out.print(ch + " ");
}
System.out.println();
}
}
}Output
