netbeans 使用右括号识别缩进错误}

j7dteeu8  于 2022-11-10  发布在  其他
关注(0)|答案(2)|浏览(129)

我尝试提交代码进行自动审查,但遇到了一些我不太理解的错误。我使用Netbeans和TMC在MOOC.fi中提交代码。具体来说,我遇到的两个错误是:

  1. Line 15: '}' should be on the same line.
  2. Line 18: '}' should be on the same line.
    下面是代码:
import java.util.Scanner;

public class CheckYourIndentation {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.println("Give a number: ");
        int first = Integer.valueOf(scan.nextLine());
        System.out.println("Give another number: ");
        int second = Integer.valueOf(scan.nextLine());
        if (first == second) {
            System.out.println("Same!"); 
        }
        else if (first > second) {
            System.out.println("The first was larger than the second!"); 
        }
        else {
            System.out.println("The second was larger than the first!");
        }

    }
}

下面是Pastebin中的代码。

vcudknz3

vcudknz31#

我需要把else ifelse放在与前一个代码块的最后一个括号相同的行上。换句话说,这是正确的最终结果:https://pastebin.com/CchVXq2M

if (first == second) {
    System.out.println("Same!"); 
} else if (first > second) {
    System.out.println("The first was larger than the second!"); 
} else {
    System.out.println("The second was larger than the first!");
}
nwo49xxi

nwo49xxi2#

我不知道为什么你看到这个问题,但我测试你的代码与我的netbeans集成开发环境和它的工作正常

相关问题