Write a Java program to print the following pattern:
1
3 2
4 5 6
10 9 8 7
11 12 13 14 1
Answers
Answered by
0
Answer:
Enter the number that you want,
like you want 5 rows.
Explanation:
import java.util.*;
public class Ascending_Number_Pyramid
{
public static void main ()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter number of rows:");
int rows = sc.nextInt();
int myNum = 1;
for ( int i = 1 ; i <= rows ; i++ )
{
for ( int j = 1 ; j <= i ; j++ )
{
System.out.println (myNum + " ");
myNum++;
}
System.out.println ();
}
}
}
Similar questions