Here is my code.
import java.util.Scanner;
public class ORR_P02 {
public static void main(String args[]){
String input;
char medium1;
double distance;
Scanner medium = new Scanner(System.in);//Scanner for user input of the type of medium
Scanner traveled = new Scanner(System.in);//Scanner for the distance traveled
System.out.print("Please enter the type of medium (Air, Water, Steel):");
input = medium.next().toLowerCase();
//this was to make sure it was changing it to lower case
System.out.println(input);
if (input == "air"||input == "water"||input == "steel"){
//used to get the first character of the input they had to match the switch case
medium1 = input.charAt(0);
switch (medium1)
{
case 'a':
System.out.println("Please enter the distance here:");
break;
case 'w':
System.out.println("Please enter the distance here:");
break;
case 's':
System.out.println("Please enter the distance here:");
break;
}
}
else{
System.out.println("Incorrect type of medium entered.");
}
}
}
What I want to do is make it so that when a user inputs something; if it doesn't match the if statement, then it just prints the else statement. The only issue is that it always prints out the else statement no matter what.
As long as the input equals air, water, or steel I want it to run the switch statements in between. That is why the charAt is there. Any ideas on how to accomplish this?