I have a java program below:
package assignment;
import java.util.Scanner;
public class Assignment {
public static void main(String[] args) {
System.out.println("Enter your age and I wil let you know if you are eligible to vote");
Scanner input = new Scanner(System.in);
int age;
age = input.nextInt();
String nationality;
nationality = "ghana";
nationality = "Ghana";
if (age>=18) {
System.out.println("Enter your nationality");
String nation = input.next();
if (nation.equals(nationality)){
System.out.println("You are eligible to vote");
}
else{
System.out.println("You are not eligible to vote");
}
}
}
Now I would like to assign the two String values, "Ghana" or "ghana" to the "nationality" variable so that when the user enters either "Ghana" or "ghana" the condition becomes true when the program gets to check the "nation" value to the "nationality" value and then executes the statement in the "if" block.
But with my above code, the program executes the "if" statement only when the user enters "Ghana". The program executes the "else" statement when the user enters "ghana".
Please kindly help me out.
Thank you.
equalsIgnoreCase#toLowerCaseor#toUpperCaseon the user's input.