+ 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?
11 Respostas
+ 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;
}
+ 3
Nikos Garcia
input your operator as a string or char.
Then use a Switch to create the associated operation
+ 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.
+ 1
What is your code?
+ 1
Share your code Nikos Garcia
+ 1
The¥AIRWeb
Why are you posting unnecessary comments?
- 3
It's on the tag Great
https://code.sololearn.com/WBGyBRdP874A/?ref=app