How can enter a whole equation, like 1 + 2. Because I can only so far ask the user to enter one digit at a time, I would like to know how I let the user enter the entire equation?
import java.util.Scanner;
public class TryCalculator {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Addition");
System.out.println("Subtraction");
System.out.println("Division");
System.out.println("Multiplication");
System.out.println("Natural Log");
System.out.println("Exponent");
System.out.println("**********************************");
Scanner scan = new Scanner(System.in);
Scanner keyboard = new Scanner(System.in);
double value1;
double value2;
String op;
System.out.println("enter a digit");
value1 = scan.nextDouble();
System.out.println("enter operation ");
op = keyboard.next();
System.out.println("enter second digit");
value2 = scan.nextDouble();
if(op.equals("+")){
System.out.println(value1 + value2);
}if(op.equals("-")){
System.out.println(value1 - value2);
}if(op.equals("/")){
System.out.println(value1 / value2);
}if(op.equals("*")){
System.out.println(value1 * value2);
}if(op.equals("^")){
System.out.println(Math.pow(value1, value2));
}if (op.equals("log")){
System.out.println(Math.log(value1));
}else{
}
}
}