-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmcatTestPattern.java
82 lines (75 loc) · 1.5 KB
/
AmcatTestPattern.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.logical;
import java.util.Scanner;
public class AmcatTestPattern {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your number for the pattern\n");
int n = scan.nextInt();
int number=0;
int firstend=0;
int lastend=0;
for (int i = 1; i <= n; i++) {
for(int j=1;j<=n;j++){
if(i==1)
{
System.out.print(j+"*");
firstend=j+1;
lastend=j;
}
else if(i==n)
{
int jvalue=j;
j=firstend;
System.out.print(j+"*");
lastend=j;
firstend++;
j=jvalue;
}
else
{
if(i%2==0){
int jvalue=j;
int firstj=0;
if(lastend==(firstend-1)){
firstj=(lastend*2)+1;
lastend=firstj;
j=firstj;
}
else{
firstj=lastend;
j=firstj;
}
System.out.print(j+"*");
//lastend=j;
lastend++;
j=jvalue;
number=firstj;
}
else
{
int jvalue=j;
int firstj=0;
/*System.out.println(number);
System.out.println(firstend-1);
System.out.println(i);*/
if(number==((firstend-1)*i)){
firstj=(number+n)+1;
number=firstj;
j=firstj;
}
else{
firstj=number;
j=firstj;
}
System.out.print(j+"*");
//lastend=j;
number++;
j=jvalue;
}
}
}
System.out.println("");
}
scan.close();
}
}