1

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?

bdrx
  • 924
  • 13
  • 31

1 Answers1

0

You must be entering not a double.
E.g. 2.15 is a double number
but 2,15 is not.

Yuriy Chulovskyy
  • 163
  • 1
  • 10