0

我尝试提交这个并且弹出一个错误说** END OF FILE detected on input - EXIT **

我无法弄清楚这意味着什么,只是为了清楚我正在尝试建立一个系统,以便在循环中输入数据,除非值为 0。谢谢。

这是我的代码:

class Main
{
    public static void main( String args[] )
    {
        int SN = 1;
        while ( SN != 0)
        {
            System.out.print("#SN : " );
            SN = BIO.getInt();
            System.out.print("#CW : " );
            int CW = BIO.getInt();
            System.out.print("#EX : " );
            int EX = BIO.getInt();
            double Mark = CW + EX;
            System.out.printf("SN= " + SN + "EX= " + EX + "CW= " + CW + "Mark= " + "%6.1f", (double) Mark / 2      );
        }
    }
}

这是生物代码:

class BIO
{
  private static final int EOF  = -1;
  private static final int NONE = -2;
  private static int nextChar = NONE;
  private static boolean EOFdetected = false;

  public static String getLineBASE()
  {
    String line = "";                                 // Line read 
    int    ch;                                        // Read ch 

    try
    {
      ch = System.in.read();                          // No next char 

      if ( ch == EOF ) 
      {
        System.out.println("**** END OF FILE " + 
                           "detected on input -- EXIT ****" );
        System.exit(-1);
      }
      while( ch != '\n'  )                            // Read loop 
      {
        if ( ch == EOF )
        {
          EOFdetected = true;
          return line;                                //  exit 
        }
        line = line + (char) ch;                      //  form line 
        ch = System.in.read();                        //  next ch 
      }
      return line;                                    // return line 
    }
    catch( IOException exp )                          // Problem 
    {
      System.exit(-1);                                // Exit ** 
    }
    return "";                                        // Blank line 
  }

 public static String getLine()
  {
    String line = getLineBASE();                      // Read line 
    //System.out.println( line ); 
    return line;
  }


  public static String getString()
  {
    String line = getLine();                          // Read line 
    return line.trim();
  }

  public static double getDouble()
  {
    String res = getLine();                           // Read line 
    double value = 0.0;                               // 
    try
    {
      value = Double.parseDouble( res.trim() );       // Convert 
    }
    catch ( NumberFormatException ex )                // Problem 
    {                                                 //  ignore 
    }
    return value;                                     // return 
  }

  public static int getInt()
  {
    String res = getLine();                           // Read line 
    int value = 0;                                    // 
    try
    {
      value = Integer.parseInt( res.trim() );         // Convert 
    }
    catch ( NumberFormatException ex )                // Problem 
    {                                                 //  ignore 
    }
    return value;                                     // return 
  }

}
4

1 回答 1

0
 try
{
  ch = System.in.read();  //reads from keyboard.

  if ( ch == EOF ) 
  {
    System.out.println("**** END OF FILE " + 
                       "detected on input -- EXIT ****" );
    System.exit(-1);
  }
}

此代码段从键盘读取输入。如果您想从文件中读取内容(我假设您是,因为有一个 EOF)查找Scanner类。如果这不是你想要的,我很抱歉,我只是在做假设。

于 2012-07-16T19:19:40.573 回答