Computer Science, asked by gitasubashini, 3 months ago

. Write a java program to display the following pattern



1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

Answers

Answered by anindyaadhikari13
7

Answer:

The given cσde is written in Java.

public class Pattern    {

   public static void main(String args[])  {

       int i,j,a=1;

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

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

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

           System.out.println();

       }

   }

}

Outer loop iterates 5 times as there are 5 rows. Inner loop iterates i times (where 'i' is the row number) as nth row has n number of columns. Initially, value of a is 1. Inside the loop, value of a is displayed and incremented by 1. A new line is displayed after displaying each row.

See the attachment for output.

•••♪

Attachments:
Answered by kamalrajatjoshi94
2

Answer:

The given pattern is a floyds triangle

Program:-

public class Demo

{

public static void main(String args[ ])

{

int a,b,p=0;

for(a=1;a<=5;a++)

{

for(b=1;b<=a;b++)

{

p++;

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

}

System.out.println();

}

}

}

Attachments:
Similar questions