Why isn't my if statement in JAVA working?

Why isn't my if statement in JAVA working?
0

#1

Hi,

I tried if(outcome1.equalsIgnoreCase("Yes")){.

However, the program runs but doesn’t being the user to that method when they input “Yes”. How can I fix this?

        System.out.println("Please enter the one of the following exactly how you see on your display 'Yes' or 'No'");
        outcome1=userinput.next();
        if(outcome1.equalsIgnoreCase("Yes")){ 
            FunctionalSkills();
        } 
       if(outcome1.equalsIgnoreCase("No")){                
       System.out.println("Thanks for using the Liam's UCAS grade calculator.");
            System.exit(0);
        }

#2

Your outcome1 variable needs to be preceded by the type String. All variables in Java must have a data type.

Also, preceding all the code you have shown and for the same reason, you need to define the type of your userinput variable. Java needs to know that userinput is the kind of variable which can accept input. Here’s one way you can do that:

import java.util.Scanner;

Scanner userinput = new Scanner(System.in);

I hope that helps!

Oh, and when you’re done, you should close the Scanner object:

userinput.close();

#4

Separate your String declarations into two lines: one with the String variables which have assignments like option4 = "Help", option5 = "Quit", and the other with the simple declarations like username, outcome1