This code is works fine when you type 22 and 56 for example, it shows you the correct result
import java.util.Scanner;
class apples{
public static void main(String args[]){
Scanner villy = new Scanner (System.in);
double fnum, snum, answer;
System.out.println("Enter first num: ");
fnum = villy.nextDouble();
System.out.println("Enter second num: ");
snum = villy.nextDouble();
answer = fnum + snum;
System.out.println(answer);
}
}
but when you try to put decimals for example 23.53 and 42.76 it fails with the following exception (see screenshot):
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 apples.main(apples.java:8)