I'm doing a calculator, in which is asked to the user to put two numbers, and then an aritmethical operator, so a set of IFs will understand what operator it is and do the operation required:
public class Calc {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("First number: ");
double num1 = input.nextDouble();
System.out.print("Second number: ");
double num2 = input.nextDouble();
System.out.print("Artithemtical operator(-, +, :, x): ");
String segn = input.nextLine();
if(segn == "+" ) {
System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
}
else if(segn == "-") {
System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
}
else if(segn == "x") {
System.out.println(num1 + " x " + num2 + " = " + (num1 * num2));
}
else if(segn == ":") {
System.out.println(num1 + " : " + num2 + " = " + (num1 / num2));
}
}
}
as you can see if the input is a specific operator it will perform the specific task. It works well, it makes you put the two numbers, the operator but then it does nothing, what shall I do?