I have tried as per below code but not able to get the desired output
`package patterns; import java.util.Scanner; public class OddSquarePattern {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int i=1;
while(i<=n) {
int j=n;
int odd= 2*i-1;
while(j>=i){
System.out.print(odd);
odd=odd+2;
j--;
}
int p=1;
while (p<=i-1) {
System.out.print(p);
p=p+2;
}
System.out.println();
i++;
}
}
} `
Aucun commentaire:
Enregistrer un commentaire