Computer Science, asked by ninja01o2, 3 months ago

Write a program in java using for loop.

('0' in the below question was not meant to be used. Please ignore all the zeros)
12345
01234
00123
00012
00001​

Answers

Answered by mdasraf1235543
0

Class pattern

{

public static void main(String args [ ] )

{

int i,j;

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

{

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

{

System.out.print(" "+ j);

}

System.out.println( );

}

}

HOPE YOU WILL UNDERSTAND AND MARK AS BRAIN LIST

Answered by anindyaadhikari13
1

Required Answer:-

Correct Question:

Write a Java program to display the following pattern.

12345

 1234

   123

     12

       1

Solution:

Here comes the program.

public class Pattern {

 public static void main(String[] args) {

    int i, j, space=0;

    for(i=5;i>=1;i--,space++) {

      for(j=1;j<=space;j++)

         System.out.print(" ");

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

        System.out.print(j);

      System.out.println();

    }

 }

}

Explanation:

  1. Outer loop determines the number of rows for the pattern.
  2. First loop inside the outer loop displays the spaces and the second loop inside the outer loop displays the number.
  3. After displaying each row, a new line is displayed.

See the attachment for output ☑.

Attachments:
Similar questions