Computer Science, asked by sagarikaash1, 11 months ago

Write a program in java to display the given pattern using nested for loop:
3
5 6
8 9 10
12 13 14 15

Answers

Answered by BhuvanBSH
1

Answer:

Hope it helps.

Explanation:

import java.io.*;

class delay

{

public static void main(String args[])

{

 int s=3;

 int j;

 int sum=0;

 for(int i=1;i<=4;i++)

 {

  for(j=s;j<=15;j++)

  {

   sum=sum+1;

   if(sum<=i)

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

  }  

  System.out.println();

  s=s+(i+1);

  sum=0;

 }

}

}

Answered by anindyaadhikari13
2

Question:-

➡ Write a program in Java to display the following pattern.

3

5 6

8 9 10

12 13 14 15

Program:-

This is the shortest approach.

class Main

{

public static void main(String s[])

{

int a=3;

for(int i=1;i<=4;i++)

{

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

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

a++;

System.out.println();

}

}

}

For verification, check out the attachment.

Attachments:
Similar questions