首页 > 解决方案 > 解析时到达文件末尾,找不到丢失的括号

问题描述

所以我知道这个错误是当缺少一个括号时,但我已经检查过并且这段代码在 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

标签: javacompiler-errorscurly-braces

解决方案


括号看起来不错。

我看到的一个错误是错字。

if (B <= 0 || H <= 0) {flaf = false;

您输入的是“flaf”,而不是 flag。

我在 Eclipse 中复制了运行你的代码,它运行良好。


推荐阅读