まず、私はこのウェブサイトの初心者ですので、私のルーキーの間違いを許してください。私の問題の第2は、私はJavaコーディング(明らかに)。しかし、私はそれを実行するたびに、正しい答えを入力しても、間違った答えをタイプしたように反応します。私の間違いを指摘していただけますか?私のifとelseコーディングがうまくいきません
import java.util.*;
public class Quiz {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
System.out.println("Hi! Welcome to the Quiz! Please insert your username.");
String userName = in.nextLine();
System.out.println("Welcome " + userName + "! Let's start! Your first question is what is the capital of Norway?");
String answer = in.nextLine();
if (answer == ("Oslo"))
System.out.println("Good Job! Your next question is how many states are there in U.S.A.?");
else
{
System.out.println("You've failed!");
}
{
@SuppressWarnings("unused")
String answer1 = in.nextLine();
if (answer1 == ("50"))
System.out.println("Well done! Your next question is where did the first football world cup happen?");
else
{
System.out.println("You've failed!");
}
String answer2 = in.nextLine();
if (answer2 == ("Uruguay"))
System.out.println("Well done! Your next question is");
else
{
System.out.println("You've failed!");
}
}
}
}
また、コーディングでループを作成する方法を学習したいと思います。たとえば、間違った答えを与えた後、質問1から自動的に再起動します。ありがとうございました –
私はEclipseはあなたの質問とは関係ないと思います。それはあなたが使っているIDEだと思われます。 –
Stack Overflowへようこそ[ツアー]、[ヘルプ]、[ask]を読んでこのサイトの仕組みを知ってください。また、あなたのコードを正しくインデントする方法を読んで、何が起こっているのかを理解することは不可能に近づいています。リンクされた/重複した質問を読んで、何が間違っているかを知る。再起動するには、 'do-while'を読んでください。 – Frakcool