Computer Science, asked by BrainlyProgrammer, 3 months ago

New Question!!
(Not a challenge but it's urgent)

WAP in JAVA to print the following pattern:-
1
232
34543
4567654
567898765
_
• Also please show your logic
(How you made this program in other words, explaination of your program)​

Answers

Answered by nancy359
7

\huge\bf{Question:}

Write a program to display following pattern:-

1 \\ 232 \\ 34543 \\ 4567654 \\ 567898765

\huge\bf{Solution:-}

  • (Refer to attachment)

★✩★✩★✩★✩★✩★✩★✩★✩★✩★✩★

\huge\sf\blue{Have \: a \: nice \: day}\

Attachments:
Answered by anindyaadhikari13
13

Answer:

This is the required Java program for the question.

import java.util.*;

public class Pattern   {

   public static void main(String args[])   {

       int n,i,j;

       Scanner sc=new Scanner(System.in);

       System.out.print("Enter the number of rows:  ");

       n=sc.nextInt();

       for(i=1;i<=n;i++)   {

           for(j=i;j<i*2-1;j++)  {

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

           }

           for(j=i*2-1;j>=i;j--)

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

           System.out.println();

       }

       sc.close();

   }

}

Explanation:

The problem is solved using nested loop. We will ask the user to enter the number of rows for the pattern. Outer loop iterates n times (where n is the number of rows) as given by the user.

Next, we will display the column. Here, the pattern is divided into two parts.

2

34

456

5678

And,

1

32

543

7654

98765

The second inner loop is for displaying the first part. Second part is just the opposite of the first (excluding the first number). Then, the third loop iterates which displays the second part.

See the attachment for output.

Attachments:
Similar questions