I’m just learning java so this is probaly a really dumb question but i can’t find a simple enough answer. I’m trying to make a make the program so if the user types “male” to run the System.out.print(“You are a guy”);
Here’s my code:
import java.util.Scanner;
public class clac {
public static void main(String[] args){
double gender;
Scanner input = new Scanner(System.in);
System.out.print("Are you male or female? ");
gender = input.nextDouble();
if (gender == "male"){
System.out.println("You are a guy");
}else{
System.out.print("You are a gal.");
}
}
}
What you are doing wrong: You need to read a String. A String is a piece of text. A double is a decimal number. You are reading a double.
How to solve it: