Write the program in java to display the following patterns
Attachments:
Answers
Answered by
0
class pro
{
public static void main()
{
System.out.println(“1”);
System.out.println(“2 1”);
System.out.println(“3 2 1”);
System.out.println(“4 3 2 1”);
System.out.println(“5 4 3 2 1”);
}
}
{
public static void main()
{
System.out.println(“1”);
System.out.println(“2 1”);
System.out.println(“3 2 1”);
System.out.println(“4 3 2 1”);
System.out.println(“5 4 3 2 1”);
}
}
Answered by
0
Answer:
public class Main{
public static void main(String[] args){
for (int i = 1; i <= 5; i++){
for(int j = i; j >= 1; j--){
System.out.print(j + " ");
}
System.out.println();
}
}
}
Explanation:
Run two different loops for Row and column and print the value of j.
First loop will run in increasing order till 5(or till whatever row you want, it can 7 or 8 or 10 or anything) and 2nd will run in decreasing order till 1.
Similar questions
Chemistry,
3 months ago
Social Sciences,
3 months ago
History,
7 months ago
Business Studies,
7 months ago
English,
11 months ago
Math,
11 months ago