-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pattern.txt
121 lines (96 loc) · 1.56 KB
/
Pattern.txt
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.Scanner;
public class Pattern {
static int c=0;
public static void main(String[] args)
{
int n;
Scanner x=new Scanner(System.in);System.out.println("");System.out.println("");
System.out.println("enter a odd number to print pattern or 0 to exit: ");
n=x.nextInt();
if(n%2!=0)
{
for(int j=0;j<n;j++) {
for(int i=0;i<n-1;i++)
{
System.out.print(" ");
}
At();
}
Star1(n);
for(int i=3;i<=n;i++)
{
if( (n%i!=0) && (i%2!=0) )
{
System.out.print(" ");
}
}
for(int i=0;i<n+2;i++)
{
System.out.print("@");
}
main(args);
}
else if(n==0)
{
System.out.println("terminated...!!");
System.exit(0);
}
else {
System.out.println("You've entered an Even number,Please Enter a odd number");
main(args);
}
}
static void Star()
{
System.out.print("*");
System.out.println("");
}
static void space(int c)
{
for(int t=0;t<c;t++)
{
System.out.print(" ");
}
}
static void Star1(int n)
{
int flag=0;
c=n-1;
for(int i=1;i<=n;i++)
{
space(c);
if(i%2!=0)
{
for(int k=0;k<i;k++)
{
System.out.print("*");
}
c--;
}
flag++;
System.out.println("");
}
if(flag==n)
{
c+=2;
int l=c;
for(int j=n-1;j>0;j--)
{
space(l);
if(j%2!=0)
{
for(int k=0;k<j;k++) {
System.out.print("*");
}
l++;
}
System.out.println("");
}
}
}
static void At()
{
System.out.print("@");
System.out.println("");
}
}