-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFull Number Pyramid
More file actions
26 lines (22 loc) · 892 Bytes
/
Copy pathFull Number Pyramid
File metadata and controls
26 lines (22 loc) · 892 Bytes
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
import java.util.Scanner;
public class ExecutionFile{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter n: ");
int n = scan.nextInt();
for(int i = 1; i <= n; i++){ // Outer loop for rows
for (int j = 1; j <= n - i; j++){ // Print spaces for alignment
System.out.print(" ");
}
int num = i; // Initialize the starting number of the row
for(int j = 1; j <= i; j++){ // Print increasing numbers
System.out.print(num++ + " ");
}
num -= 2; // Adjust to the last printed number before decrementing
for(int j = 1; j < i; j++){ // Print decreasing numbers
System.out.print(num-- + " ");
}
System.out.println(); // Move to the next row
}
}
}