I am having trouble getting this program to work properly, it takes 2 numbers then does the type of math you tell it to do. I wrote this just to refresh my memory having not worked with java for a few months. Here is the code:
import java.util.Scanner;
public class math {
public static void main(String[] args){
Scanner one = new Scanner(System.in);
Scanner two = new Scanner(System.in);
System.out.print("Enter a number: ");
int n1 = one.nextInt();
System.out.print("Enter a second number: ");
int n2 = one.nextInt();
System.out.print("Add, subtract, multiply, or divide? ");
String f = two.nextLine();
System.out.println(f);
if (f=="add"){
System.out.println(n1 + n2);
}else if (f=="subtract") {
if (n1>n2){
System.out.println(n1 - n2);
}else{
System.out.println(n2 - n1);
}
}else if (f=="multiply"){
System.out.println(n1 * n2);
}else if (f=="divide"){
if (n1>n2){
System.out.println(n1 / n2);
}else{
System.out.println(n2 / n1);
}
}
}
}
Edit: Thank you all, it works with f.equals()