how to have multiple conditions in an if statement java

//Program to check if the answer to the given question is correct
//with multiple conditions in a single else if statement
import java.util.Scanner;
public class MultipleChoiceQuestion {
    public static void main(String args[]) {
        String question = "How many types of loops exist? ";
        String choiceOne = "One";
        String choiceTwo = "Two";
        String choiceThree = "Three";

        String correctAnswer = choiceThree;

        // Write a print statement asking the question
        System.out.println(question);
        // Write a print statement giving the answer choices
        System.out.println(choiceOne);
        System.out.println(choiceTwo);
        System.out.println(choiceThree);
        // Have the user input an answer
        Scanner sc = new Scanner(System.in);
        // Retrieve the user's input
        String answer = sc.next();

        // If the user's input matches the correctAnswer...
        // then the user is correct and we want to print out a congrats message to the user.
        if (answer.equals(choiceThree)) {
            System.out.println("Congrats! It's the correct answer!");
        }
        // If the user's input does not match the 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.
        else if (answer.equals(choiceOne) || answer.equals(choiceTwo)){
                System.out.println("Sorry wrong answer. The correct answer is "+choiceThree);
            }
        else{
                System.out.println("Incorrect Input! Check again!");
            }

}
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source