Computer Science, asked by Sonu4393, 15 hours ago

WRITE A JAVA PROGRAM TO BELOW PATTERN:

15 14 13 12 11
10 9 8 7
6 5 4
3 2
1​

Answers

Answered by LeelaGhosh1
6

Required Program (in java) -

public class Pattern{

public static void main(String args[]){ //main method.

//Here, no. of rows is fixed at 5.

//Also, the pattern begins by default with the number 15.

int n = 15;

for(int i=5;i>=1;i--){

for(int j=1;j<=i;j++){

System.out.print(n + " "); //Print the number followed by a space.

n--;

} //inner loop is closed.

System.out.println(""); //To move to next line.

} //outer loop is closed

} //main() is closed

} //class is closed

Algorithm -

  • Set the variable for printing the numbers (n) to 15.
  • Begin outer loop for no. of terms in a single row
  • Begin inner loop for printing the terms in the current row.
  • Keep decrementing n in the inner loop.
  • Move to the next line in the outer loop.
  • Move to next iteration of outer loop and continue...

Output -

=> Refer to attachment for output.

Attachments:
Similar questions