how do I let a user input a "*" and enter it into a case? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how do I let a user input a "*" and enter it into a case?

so im trying to make a calculator where the user can input an equation and choose the type (+,-,*,/) but i cant seem to figure out how to do it any ideas?

19th May 2022, 9:53 PM
Nikos Garcia
7 Answers
+ 4
Nikos Garcia You can take character (+, -, *, /) input and apply in switch statement like this: Scanner sc = new Scanner (System.in); char c = sc.next().charAt(0); System.out.println (c); switch (c) { case '+': System.out.println ("add"); break; }
20th May 2022, 6:25 AM
A͢J
A͢J - avatar
+ 3
Nikos Garcia input your operator as a string or char. Then use a Switch to create the associated operation
20th May 2022, 1:03 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
The¥AIRWeb He asked how to take * as an input. What you didn't understand here? Simply he wants to make a calculator and taking +, -, *, / as an input and want to put this in switch case. I don't think it's a meaningless question. Everyone understood question except you only.
20th May 2022, 6:16 AM
A͢J
A͢J - avatar
+ 1
What is your code?
19th May 2022, 10:37 PM
Justice
Justice - avatar
+ 1
Share your code Nikos Garcia
19th May 2022, 11:42 PM
Chris Coder
Chris Coder - avatar
+ 1
The¥AIRWeb Why are you posting unnecessary comments?
20th May 2022, 3:07 AM
A͢J
A͢J - avatar
20th May 2022, 8:40 PM
Michael K Appiah