Computer Science, asked by gungun16181, 3 months ago

Write a program in Java to display the following pattern. The program should [5]

accept the rows to be printed using the scanner class. For example, if the user

enters 7 the following pattern gets printed

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

16 17 18 19 20 21

22 23 24 25 26 27 28​

Answers

Answered by BrainlyProgrammer
1

Answer:

int c=1;

n=Sc.nextInt();

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

{

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

{

System.out.print(c); //prints the value of c

c++; //increases the value of c

}

System.out.print(); //goes to next line

}

Answered by anindyaadhikari13
2

Question:-

Write a program to display the following pattern.

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

16 17 18 19 20 21

22 23 24 25 26 27 28

Program:-

class Pattern

{

public static void main(String args[])

{

int a=1;

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

{

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

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

System.out.println("\n");

}

}

}

Similar questions