Computer Science, asked by Mandy1012, 1 year ago

Q22. Write a java program toprint the following pattern.
….5
…45
..345
.2345
12345

Answers

Answered by salonisingh160oztp48
60

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.

Answered by qwnerazzuri
3

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.

Similar questions