-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddSquare.java
More file actions
45 lines (42 loc) · 951 Bytes
/
OddSquare.java
File metadata and controls
45 lines (42 loc) · 951 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
35
36
37
38
39
40
41
42
43
44
45
// Problem
// Result
// 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
import java.util.Scanner;
public class OddSquare {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int num = (2 * n) - 1;
for (int row = 1; row <= n; row++) {
int start_Value = 2 * row - 1;
for (int col = 1; col <= n; col++) {
if (start_Value > num) {
start_Value = 1;
}
System.out.print(start_Value);
start_Value += 2;
}
System.out.println();
}
s.close();
}
}