How do I compare a string with multiple words in an if/then statement? I tried this:
System.out.println("How would you describe your active lifestyle? Sedentary, Somewhat Active, or Active?");
String lifestyle = sc.next();
double activity;
if(lifestyle.equalsIgnoreCase("sedentary"))
{
activity = 0.2;
}
else if(lifestyle.equalsIgnoreCase("somewhat active"))
{
activity = 0.3;
}
else
{
activity = 0.5;
}
But when you enter "somewhat active", it assigns the variable activity to 0.5. How can I get it to register that "somewhat active" is a thing?
Aucun commentaire:
Enregistrer un commentaire