一个JAVA题目
设计一个JAVA程序,打印N阶螺旋矩阵:当N=3时,则1 2 3
8 9 4
7 6 5
请大家帮我解决一下
public class Ring{
public static int getNum(int n,int i,int j){
if(i==0) return j+1;
else if(i==n-1) return 3*n-j-2;
else if(j==0) return 4*n-i-3;
else if(j==n-1) return n+i;
else return 4*(n-1)+getNum(n-2,i-1,j-1);
}
public static void print(int n){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) System.out.printf(\"%7d\",getNum(n,i,j));
System.out.println();
}
}
public static void main(String[] args){
Scanner scan =new Scanner(System.in);
while(true){
System.out.println(\"input a integer(0 to exit):\");
int n =scan.nextInt();
if(n<=0) break;
print(n);
}
}
}
有错误哎!!!
E:\练习\Ring.java:16: cannot find symbol
symbol : class Scanner
location: class Ring
Scanner scan =new Scanner(System.in);
^
E:\练习\Ring.java:16: cannot find symbol
symbol : class Scanner
location: class Ring
Scanner scan =new Scanner(System.in);
^
2 errors
Process completed.
[此贴子已经被作者于2007-10-31 22:21:59编辑过]