+ 1
How can I make the user input mathematical operator and I solve the operation and print the result?
2[. ]3=result
2 Answers
+ 12
Accept the operator as char (like +,-,*,/,%). Scanner class doesn't have any separate method to take char input. So take the input as String using next() and consider the 1st character of it as the char input.
Scanner scan = new Scanner (System.in);
char operator = scan.next().charAt(0);
// charAt(0) refers to the 1st character
+ 3
Agreeing with @shamima, further if you want to test what operator it was you can identify it by switch or if else statement and comparing the anscii value of the character with that you want it to be.