Skip to content

learning-java-2825378-03_07b (Code gives incorrect answer even when I type Jupiter) Help #47

@tnbythewood

Description

@tnbythewood

import java.util.Scanner;

public class Main {

public static void main(String args[]) {
    String question = "What is the largest planet in the solar system?";
    String choiceOne = "Earth";
    String choiceTwo = "Jupiter";
    String choiceThree = "Mars";

    String correctAnswer;
    correctAnswer = choiceTwo;

    // Write a print statement asking the question
    {System.out.println("What is the largest planet in the solar system?");}
    // Write a print statement giving the answer choices
    {System.out.println("Choose one of the following:" + " " + "Earth," + " " + "Jupiter," + " " + "Mars");}
    // Have the user input an answer
        Scanner scanner = new Scanner(System.in);
    // Retrieve the user's input
    String input = scanner.next();
    // If the user's input matches the correctAnswer...
    if(choiceTwo.equals(input.toLowerCase()))
    // then the user is correct and we want to print out a congrats message to the user.
    {System.out.println("Congrats! You are correct!");}
    // If the user's input does not match the correctAnswer...
    else {System.out.println("Incorrect, the correct answer is" + " " + correctAnswer);}
    // then the user is incorrect and we want to print out a message saying that the user is incorrect as well as what the correct choice was.

}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions