-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise4.java
More file actions
34 lines (34 loc) · 1009 Bytes
/
Exercise4.java
File metadata and controls
34 lines (34 loc) · 1009 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
/*
Algo-:
1. accept the value of n;
2. repeat for i vary from 1-n --used to keep track of no. of rows
2.1 repeat for j vary from i-(n-i) ---print the initial blank spaces
2.1.1 repeat for j vary from 1-i ---print the no. from 1 to n
2.1.1.1 repeat for j vary from (i-1)-1 ---in roeach w to print the susequent no. in the row
*/
package chapter01;
import java.util.Scanner;
/**
*
* @author harsh
*/
public class Exercise4 {
public static void main(String[] args){
int n,i,j;
System.out.println("Enter the no. : ");
n = Integer.parseInt(new Scanner(System.in).nextLine());
for(i=1;i<=n;i++){
//space
for(j=1;j<=n-i;j++){
System.out.println(" ");
}
for(j=1;j<=i;j++){
System.out.println(j+" ");
}
for(j=i-1;j>0;j--){
System.out.println(j+" ");
}
System.out.println();
}
}
}