i/p:3Question No:1
53135
313
1
313
53135
import java.util.Scanner;
public class Pat {
public static void main(String[] args) {
int n=3;
int sum=2*n+1;int sp=-1;int flag=0;
for(int i=1;i<=2*n-1;i++){
if(i<=n){
sp++;
sum=sum-2;
}
else{
sp--;
sum=sum+2;
}
for(int j=1;j<=sp;j++){
System.out.print(" ");
}
int temp=sum;flag=0;
for(int k=1;k<=sum;k++){
if(flag==0){
System.out.print(temp);
temp=temp-2;
if(temp<1){
flag=1;
temp=temp+2;
}
}
else{
temp=temp+2;
System.out.print(temp);
}
}System.out.println();
}
}
}
No comments:
Post a Comment