こんにちは、私はクイズアプリを作りたいと思っています。g.間違った位置での一致?プログラムは毎回終了します
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");
}
}
}
}
私の質問は、どこに文字列g = scan.NextLineを配置する必要があるのですか?私はコンソールの出口だけのコンパイルエラーは表示されません。 私はそれをIF文と他のいくつかのポジションに置いてみましたが、ただ止めました。助けてください。
閉じるのではなく、一時停止するように...キーを押すと閉じます。 –
それはあなたの入力を待っている可能性があります – PimJ
あなたの入力が与えられた(キーを押した)とき、プログラムはランタイムエラーのために終了することがあります。コマンドラインからアプリを実行してみてください: http://stackoverflow.com/questions/16137713/how-to-run-a-java-program-from-the-command-line – PimJ