0

What is wrong in code? The program does not start.

calculator on Java https://code.sololearn.com/cQPvW277Q1M3/?ref=app

8th Mar 2020, 8:23 PM
Lytvynenko Yurii (/IceBear)
Lytvynenko Yurii (/IceBear) - avatar
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
8th Mar 2020, 8:48 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
IceBear Your welcome :)
9th Mar 2020, 11:51 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
zemiak Ah, I did not realize the changes with switch statements. When I learned switch it was not possible. Thank you.
11th Mar 2020, 9:46 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks
9th Mar 2020, 7:50 PM
Lytvynenko Yurii (/IceBear)
Lytvynenko Yurii (/IceBear) - avatar
+ 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)
11th Mar 2020, 2:38 AM
zemiak