gpt4 book ai didi

java - g.等于位置错误?程序每次都会关闭

转载 作者:行者123 更新时间:2023-12-02 02:58:59 25 4
gpt4 key购买 nike

你好,我想制作一个测验应用程序,到目前为止我已经做到了。

import java.util.Scanner;
public class Brotcrunsher {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);

System.out.println ("Hallo");
System.out.println ("Welcome to the test");
System.out.println ("If you are the admin of the test and would like to edit it please type the password now");
System.out.println ("Otherwhise please say 'begin' to start");
String c = scan.nextLine();
if (c.equals ("edit")) {
System.out.println ("Editor mode coming soon, please edit via code");
}
else {
if (c.equals ("begin")) {
} // end of if
System.out.println ("A flag has more then 1 color right?");
String a = scan.nextLine();
if (a.equals("ja")) {
System.out.println ("You arent dumb, nice.");
System.out.println ("What is 352 + 223");
int b = scan.nextInt();
if (b == 575) {
System.out.println ("That is correct nice");
System.out.println ("You passed the basic questions, going to be tricky now");
System.out.println ("What was the date when Donald Trump became president");
String g = scan.nextLine();
System.out.println ("A = 19.01 B = 20.01 C = 21.01 D= 22.01");
if (g.equals ("B")){
System.out.println ("You are right, lets move on.");
} // end of if
else {
System.out.println ("That is wrong. Better luck next time");
} // end of if-else
}
else {
System.out.println("That isn't right, you failed.");
System.out.println ("If you'd like to repeat the test, go ahead and do so");
}
}
else {
System.out.println ("You arentn a genie");
}
}
}
}

所以我的问题是我需要将 String g = scan.NextLine 放置在哪里才能使其正常工作?我没有收到任何编译错误,只是控制台退出。我尝试将它放在 IF 语句的开头和其他一些位置,但它就停止了。请帮忙。

最佳答案

如果控制台在您运行应用程序时关闭,那么您可能会收到运行时错误。尝试从已打开的命令 shell 运行您的程序以查看错误。

这应该是一条评论,但我没有足够的代表 0:)

关于java - g.等于位置错误?程序每次都会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42647280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com