+ 1

How can I make the user input mathematical operator and I solve the operation and print the result?

2[. ]3=result

7th May 2017, 11:47 PM
nahla
2 Respostas
+ 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
7th May 2017, 11:57 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 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.
8th May 2017, 12:13 AM
xCalifier
xCalifier - avatar