Odd Square in java Eclipse

Published: 13 February 2023
on channel: Education Club
135
2

Odd Square in java Eclipse

Q4:-Odd Square
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


Solution:-

import java.util.Scanner;
public class OddSquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i=1;
int maxodd=(2*n)-1;
while(i#=n) {
int j=1;
int odd=(2*i)-1;
while(j#=n) {
if(odd$maxodd) {
odd=1;
}
System.out.print(odd);
j++;
odd=odd+2;
}
System.out.println();
i++;
}
}
}


On this page of the site you can watch the video online Odd Square in java Eclipse with a duration of hours minute second in good quality, which was uploaded by the user Education Club 13 February 2023, share the link with friends and acquaintances, this video has already been watched 135 times on youtube and it was liked by 2 viewers. Enjoy your viewing!