1
import java.io.*;
public class MgSq
{
    public static BufferedReader input = new BufferedReader(new 
public
InputStreamer(System.in));
    public static void main (String args[]) throws Exception
    {

      int w, x, y, z, b, key;
      boolean n_ok;
      int [] [] square = new int [15] [15];
      {
         System.out.print("Size of square? ");
         b = Integer.parseInt(input.readLine());
     n_ok = (z<=b) & (b<=15+1) & (b%2==1);
         if ( n_ok )
      {
               for (w=0;w<b;w++)
               for (x=0;x<b;x++) square[w][x] = 0;
               square[0][(int)(b-1)/2] = 1;
               key = 2;
               w = 0;
               x = (int)(b-1)/2;
               while ( key <= b*b )
           {
           y = w - 1;
           if ( y < 0 ) y = y + b;
               z = x - 1;
           if ( z < 0 ) z = z + b;
               if ( square[y][z] != 0 ) w = (w+1) % b;
               else 
           { 
        w = y; x = z;
           }
               square[w][x] = key;
               key = key + 1;
           }
         System.out.println("Magic square of size " + b);
         for (w=0;w<b;w++)
            {
               for (x=0;x<b;x++)
                  System.out.print("\t"+square[w][x]);
               System.out.println();
            }
         }      

    }
         System.out.println("Error in number, try again.");
}
}

我不断收到以下错误:

MgSq.java:4 error: cannot find symbol 
public static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

symbol: class InputStreamer
class: MgSq
4

5 回答 5

3

由于您 import only java.io.*InputStreamer可能是一个错字,您想InputStream改用它。

于 2013-03-18T14:21:01.317 回答
1

更改InputStreamerInputStreamReader

于 2013-03-18T14:21:27.063 回答
1
public static BufferedReader input = new BufferedReader(new 
public
InputStreamer(System.in));

应该

public static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
于 2013-03-18T14:23:29.993 回答
1

以下行中的第二个public没有意义:

public static BufferedReader input = new BufferedReader(new 
public 
InputStreamer(System.in));

将其更改为

public static BufferedReader input = new BufferedReader(new InputStreamer(System.in));

显然InputStreamer不是一个真正的班级。正如其他人所说,尝试InputStreamReaderInputStream

于 2013-03-18T14:20:19.923 回答
1

public从之前删除new InputStreamReader

于 2013-03-18T14:20:33.920 回答