Q22. Write a java program toprint the following pattern.
….5
…45
..345
.2345
12345
Answers
Answer:
public class Pattern
{
public static void main(String[]args)
for(int i = 5; i >= 1; i --)
{
for(int j = i ; j< =5; j++)
{
System. out.print(j);
}
System.out.println();
}
}
Hope it helps.mark as brainliest.
The Java program to print the pattern is as follows:
public class Main
{
public static void main(String[] args) {
for(int i = 5; i >= 1; i --){
for(int k = i-1 ; k>=1;k--){
System.out.print('.');
}
for(int j = i ; j <= 5; j++){
System. out.print(j);
}
System.out.println();
}
}
}
Here, we have used 3 "for" loops. 1st loop is for printing the number of columns, we have used reversed loop, now the 2nd loop is for printing dots and the 3rd loop is used for printing the number of rows.