write a program in java to print
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
Answers
Answered by
2
The program to this question can be given as:
Program:
class Main //defining main class
{
public static void main(String a[]) //defining main method
{
int i,j; //defining variable
for(i=1;i<=5;i++) //outer loop for column
{
for(j=5;j>=i;j--) //inner loop for row
{
System.out.print(j); //print value.
}
System.out.print("\n"); //print space.
}
}
}
Output:
54321
5432
543
54
5
Explanation:
- In the above java program, the class 'Main' is defined that contains the main method. Inside the main method, two integer variable "i and j" is declared that is used in the loop.
- In the next line for loop is declare that prints the given pattern.
- The outer loop is used for print columns and the inner loop is used for print rows.
- Inside a loop, the variable j value is printed and for the next line, we use '\n'.
Learn more:
- Learn pattern in java: https://brainly.in/question/6773823
Similar questions