【问题标题】:reached end of file while parsing, cannot find missing bracket解析时到达文件末尾,找不到丢失的括号
【发布时间】: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


【解决方案1】:

括号看起来不错。

我看到的一个错误是拼写错误。

如果 (B

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多