Computer Applications
Write a program in Java to display the following pattern:
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
Java
Java Nested for Loops
ICSE
64 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 5, j = 1; i >= 1; i--, j++) {
for (int k = 1; k <= j; k++)
System.out.print(i + " ");
System.out.println();
}
}
}
Output
![BlueJ output of Write a program in Java to display the following pattern: 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1 BlueJ output of Write a program in Java to display the following pattern: 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1](https://cdn1.knowledgeboat.com/img/java-programs/solutions-p33-1.jpg)
Answered By
30 Likes