I am making a basic calculator purely for study purposes. Here is the block of code in question:
Scanner Operation = new Scanner(System.in);
Scanner data = new Scanner(System.in);
String add,sub,mul,div;
double fnum, snum, answer;
add= Operation.nextLine();
System.out.println(add);
if (Operation.equals("add")) {
System.out.println("Enter the first number: ");
fnum= data.nextDouble();
System.out.println("Enter second number: ");
snum= data.nextDouble();
answer = fnum+snum;
System.out.println("Your answer is "+ answer);
}
The program asks for two inputs and terminates without running the if statement.
Any help would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire