+ 1

Can't figure out what's wrong.

I was trying to make a temperature scale converter. But everytime i got new erorr(s). This time: Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextDouble(Unknown Source) at ConverterAdvanced.main(ConverterAdvanced.java:8) Pls, help. What am I doing wrong? The code itself: import java.util.Scanner; public class ConverterAdvanced { public static void main(String[] args) { Scanner choose = new Scanner(System.in); Scanner temp = new Scanner(System.in); Double temper = temp.nextDouble(); System.out.println("Choose your scale: Cs Fh Kl"); System.out.println(choose.nextLine()); Double resCstoFh = 1.8 * temper + 32; Double resCstoKl = temper + 273.15; Double resFhtoCs = (temper - 32) * 5 / 9; Double resFhtoKl = (temper + 459.67) * 5 / 9; Double resKltoFh = temper * 1.8 - 459.67; Double resKltoCs = temper - 273.15; final String Cs = "Cs"; final String Fh = "Fh"; final String Kl = "Kl"; String choice = choose.nextLine(); try { if (Cs.equals(choice)) { System.out.println("Enter temperature:" + temp.nextDouble()); System.out.println("Fahrenheit" + resCstoFh); System.out.println("Kelvin" + resCstoKl); } else if (Fh.equals(choice)) { System.out.println("Enter temperature:" + temp.nextDouble()); System.out.println("Celsius" + resFhtoCs); System.out.println("Kelvin" + resFhtoKl); } else if (Kl.equals(choice)) { System.out.println("Enter temperature:" + temp.nextDouble()); System.out.println("Celsius" + resKltoCs); System.out.println("Fahrenheit" + resKltoFh); } } catch (Exception e) { System.out.println("Error"); } } }

1st Mar 2017, 1:12 PM
Alex Mladich
Alex Mladich - avatar
4 ответов
+ 10
I published a working version based on your code at the playground: https://code.sololearn.com/cob1t33DiOU8/?ref=app Hope it can help you to fix your problems. If you have any further questions feel free to ask.
1st Mar 2017, 5:00 PM
Tashi N
Tashi N - avatar
+ 2
Thanks for your help!
1st Mar 2017, 10:25 PM
Alex Mladich
Alex Mladich - avatar
+ 1
obviously you are not entering a proper double value when your program expects it at System.in
1st Mar 2017, 7:44 PM
Konstantin Eremin
Konstantin  Eremin - avatar