【发布时间】:2021-07-09 14:47:51
【问题描述】:
所以我知道这个错误是因为缺少一个括号,但是我已经检查过并且这个代码在 IntelliJ 中工作,所以任何想法可能导致它或者我只是这么盲目:(
class Solution {
static int B;
static int H;
static boolean flag = true;
static Scanner scanner = new Scanner(System.in);
static {
int B = scanner.nextInt();
int H = scanner.nextInt();
scanner.close();
try {
if (B <= 0 || H <= 0) {
flaf = false;
throw new Exception ("java.lang.Exception: Breadth and height must be positive");
}
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
}
public static void main(String[] args){
if(flag){
int area=B*H;
System.out.print(area);
}
}//end of main
}//end of class
【问题讨论】:
-
这是一个很好的文件,没有任何问题(除了缺少导入语句)。你在哪里看到错误?它到底说了什么?
-
try-catch
flaf中的错字应该是flag。
标签: java compiler-errors curly-braces