0
What is wrong in code? The program does not start.
calculator on Java https://code.sololearn.com/cQPvW277Q1M3/?ref=app
5 Respuestas
+ 3
On sololearn you can have only one scanner object. I created a static scanner which you can use inside the methods.
String does not work in switch statements. To get a char you can use this trick:
char operation = sc.next().charAt(0);
The if statements to get the user input are not working. I am not sure why.
I removed them and replaced them with return sc.nextDouble();
Input: 4 5 +
Output: 9.0
https://code.sololearn.com/cE6NvMM6QDYD/?ref=app
+ 2
IceBear Your welcome :)
+ 2
zemiak Ah, I did not realize the changes with switch statements. When I learned switch it was not possible. Thank you.
+ 1
Thanks
+ 1
for Sololearn:
// use one Scanner
public class Main {
static Scanner sc = new Scanner(System.in);
// in getOperation(), use next() instead nextLine()
//if (sc.hasNextLine()) {
if (sc.hasNext()) {
//operation = sc.nextLine();
operation = sc.next();
(Strings works with switch since java 7)