0

First of all i am compete noob in Java. I tried to get the user input. Eclipse shows this error whenever i try to type double variable:

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 lesson1.MyClass.main(MyClass.java:10)

This is my code so far:

import java.util.Scanner;

public class MyClass {

public static void main(String[] args) {
Scanner scan1 = new Scanner(System.in);
System.out.println("Enter some decimal value");
double userInput = scan1.nextDouble();
System.out.println("The entered value is ");
System.out.print(userInput);
}
nitind
  • 19,089
  • 4
  • 34
  • 43

1 Answers1

0

Above codes are right! You must ensure input decimal, such as 12.3 Below is my test: Test Result

navylover
  • 12,383
  • 5
  • 28
  • 41