I have written the following code:
package buck;
import java.util.Scanner;
class apples {
public static void main(String args[]) {
Scanner bucky = new Scanner(System.in);
double fnum, snum, answer;
System.out.println("Enter first number: ");
fnum = bucky.nextDouble();
System.out.println("Enter second number: ");
snum = bucky.nextDouble();
answer = fnum + snum;
System.out.println(answer);
}
}
When I mention a double number when entering the first number, it doesn't go to the second instruction and I get what is follow:
Enter first number:
12.2
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 buck.apples.main(apples.java:10)
Can you help me with that?