java - 解析时到达文件末尾,找不到丢失的括号
问题描述
所以我知道这个错误是当缺少一个括号时,但我已经检查过并且这段代码在 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
解决方案
括号看起来不错。
我看到的一个错误是错字。
if (B <= 0 || H <= 0) {flaf = false;
您输入的是“flaf”,而不是 flag。
我在 Eclipse 中复制了运行你的代码,它运行良好。
推荐阅读
- visual-studio - VS2019 显示更新通知,但 VSIX 扩展安装程序显示已安装更新
- jquery - 如何使用 AJAX 将 JSON 发送到 Django URL?
- vue.js - 无法让 twitter Oauth 身份验证与 nuxt-auth 一起使用
- javascript - 如何使用 Python Selenium 通过 aria-label 查找并单击 JavaScript 按钮?
- spring-boot - 如何将 RefreshScope 与启用的引导程序一起使用
- javascript - 在 React 中使用 [...Array(stateValue)] 时遇到问题。不确定这是否是正确的方法
- ruby-on-rails - Rails 使用 zip 按年份匹配的两个变量
- go - Golang 导入问题
- python - 使用 scipy 和 matplotlib 绘制信号频谱图(表面肌电图)
- django - BSModalDeleteView (django-bootstrap-modal-form) 忽略 get_success_url