I've written a code for Body Mass Index which takes the weight & height in Pounds - Inches and converts to Kg - Meters and then calculates BMI.
The problem is whenever I try to run the program an error appears says:
"Exception in thread "main" java.util.InputMismatchException"
and these following lines:
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at BMI.main(BMI.java:12)"
I've been trying to solve it for 2 hours but no dice, I don't know what is needed to be changed exactly.
Here's my code
import java.util.Scanner;
public class BMI {
public static void main(String[] args) {
// TODO Auto-generated method stub
final double KgPerPound= 0.45359237;
final double MetersPerInch= 0.0254;
Scanner input= new Scanner(System.in);
System.out.println("Enter weight in Pounds: ");
double Weight = input.nextDouble();
System.out.println("Enter Height in Inches: ");
double Height = input.nextDouble();
double P_to_KG = (Weight * KgPerPound);
double I_to_M = (Height * MetersPerInch);
double BMI = (P_to_KG / Math.pow(I_to_M, 2));
System.out.println("BMI is = " + BMI );
}
}
I'm completely new to programming so I'm sorry for my newbie question :)