-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern4.java
58 lines (55 loc) · 1.43 KB
/
Pattern4.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Week 8 : Programming Assignment 4
QN : Write a program to print symmetric Pascal's triangle of "*" 's of height "l" of odd length . If input "l" is even then your program will print "Invalid line number".
For example:
input : 5
output:
*
* *
* * *
* *
*
input : 6
output:
Invalid line number
Answer is given below for --+ NPTEL +--
...............................................................................*/
import java.util.*;
public class Pattern4 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
int k ;
// Add the necessary code in the below space
if(n % 2 == 0)
System.out.print("Invalid line number");
else{
for(int i = 0; i < n; i++){
k = 0;
if(i <= n/2){
for(int j = n - i; j > n/2 + 1;j--){
System.out.print(" ");
}
while(k < ( i + 1 )){
System.out.print("*" + " ");
k++;
}
}
else{
for(int j = n-i; j < n/2 + 1;j++)
System.out.print(" ");
while(k < (n- i )){
if(k == n-i-1)
System.out.print("*");
else{
System.out.print("*");
System.out.print(" ");
}
k++;
}
}
if(i != n-1)
System.out.println( );
}
}
}
}