解析时到达文件末尾,找不到缺少的括号

4dbbbstv  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(362)

我知道这个错误是在缺少一个括号的情况下发生的,但是我已经检查过了,这段代码在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
e3bfsja2

e3bfsja21#

括号看起来不错。
我看到的一个错误是打字错误。
如果(b<=0 | | h<=0){flaf=false;
你输入了“flaf”而不是flag。
我复制了一个在eclipse中运行您的代码的脚本,它运行良好。

相关问题