-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.java
More file actions
37 lines (32 loc) · 956 Bytes
/
Copy pathQ4.java
File metadata and controls
37 lines (32 loc) · 956 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
27
28
29
30
31
32
33
34
35
36
37
package coding_wizard;
import java.util.*;
public class Q4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
int p = n / 2, t = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= p; j++)
System.out.print(" ");
int count = t / 2 + 1;
for (int k = 1; k <= t; k++) {
System.out.print(count);
if (k <= t / 2)
count--;
else
count++;
}
System.out.println();
if (i <= n / 2) {
p = p - 1;
t = t + 2;
}
else {
p = p + 1;
t = t - 2;
}
}
}
}