4

我想在最近几个小时的命令提示符下运行下面的简单代码。仍然无法修复错误。程序不编译。什么是错误

这里有什么问题。我无法找到。

下面是代码:

public static void main(String[] args) { 
     int i; 
     try { 
      DataInputStream din = new DataInputStream(System.in); 
      i = Integer.parseInt(din.readLine()); 
     } 
     catch(NumberFormatException || IOException exception) { 
      System.out.println(exception.getMessage()); 
     } 
} 
+2

只是注意:如果您打算在try-catch块后处理'i',你会得到另一个错误;) –

回答

10

需要使用单|操作。不是||

catch(NumberFormatException | IOException exception) 
+1

爱是爱的Java 7的语法糖:) –