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++;
}
}
}
In questa pagina del sito puoi guardare il video online Odd Square in java Eclipse della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Education Club 13 febbraio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 135 volte e gli è piaciuto 2 spettatori. Buona visione!