星期三, 10月 04, 2006

Solution to COMP201 quiz 3 q2

import java.util.*;


public class quiz32{
public static void main(String [] args){
Scanner k = new Scanner(System.in);
int no;

System.out.print("size ?");
no = k.nextInt();

for(int r=1; r<=no/2; r++){


for(int c=1; c<=no; c++){
if(c==r){
System.out.print(r);
}
else if(c+r==no+1){
System.out.print(r);
}
else {
System.out.print(" ");
}
}
System.out.println();
}

for(int b=1; b<=no; b++){
System.out.print(" ");
if(b+1==no-b){
System.out.print(b+1);
}

}
System.out.println();

for(int a=1; a<=no/2; a++){

for(int d=1; d<=no; d++){
if(a+d==no/2+1){
System.out.print(d);
}
else if(d-a==no/2+1){
System.out.print(no/2+1-a);
}
else {
System.out.print(" ");
}
}

System.out.println();
}

}
}

沒有留言: