Advertisements
Advertisements
Question
Write the program to display the following pattern:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Answer in Brief
Solution
public class Q9e
{ public static void main(String ar[])
{
System.out.println("\n----------------");
k = 0;
for (i = 5; i >= 1; i--)
{
for (p = 0; p < k; p++) // loop to print spaces
System.out.print(" ");
k++;
for(j = i; j >= 1; j--)
System.out.print(i);
System.out.printIn();
}
shaalaa.com
Is there an error in this question or solution?
Chapter 1.1: Nested Loop - EXERCISES [Page 146]