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