-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOdd_Square_pattern.txt
More file actions
63 lines (55 loc) · 1.11 KB
/
Copy pathOdd_Square_pattern.txt
File metadata and controls
63 lines (55 loc) · 1.11 KB
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
Odd Square
Send Feedback
Write a program to print the pattern for the given N number of rows.
For N = 4
1357
3571
5713
7135
Input Format :
A single integer: N
Output Format :
Required Pattern
Constraints :
0 <= N <= 50
Sample Input 1 :
3
Sample Output 1 :
135
351
513
Sample Input 2 :
5
Sample Output 2 :
13579
35791
57913
79135
91357
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Write your code here
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int i =1;
while(i<=n){
int j = 1;
int x = 2*i -1;
int y = 2*n -1;
int z = 1;
while(j<=n){
if(j<=n && x<=y){
System.out.print(x);
x = x+2;
}else if(j<=n && x>y){
System.out.print(z);
z = z+2;
}
j = j+1;
}
System.out.println();
i = i+1;
}
}
}