I am building a basic calculator and this is my first program in Java after reading about.. 2 tutorials and I am having a hard time getting the program to check the input on the string and run code if that input satisfies the condition.
The user inputs either +, -, * or /
I want to check to see if the input is a +, if it is then run the code. So far it runs no matter what you enter, null or otherwise.
Here is my code - let's not judge if it is crap.. you started this way (maybe);
import java.io.*; public class Main { public static void main (String args[]) throws IOException { InputStreamReader inStream = new InputStreamReader(System.in); BufferedReader readIN = new BufferedReader(inStream); System.out.println("Multiply | Divide | Add | Subtract"); System.out.println(" * | / | + | - "); try { System.out.println("What operation?"); String oprt = readIN.readLine(); /*if(oprt != null){ System.out.println("Null entry detected."); System.out.println("End of program. Press any key to terminate."); }*/ if("+".equals(oprt));{ System.out.println("You selected addition!"); } System.out.println( oprt ); } catch (IOException err){ System.out.println("Error reading input."); } System.out.println("End of program. Press any key to terminate."); String termin = readIN.readLine(); } }