thread * main * java.util.InputMismatchException中的异常

时间:2014-09-03 02:27:39

标签: java main inputmismatchexception

package Myth;

import java.util.Scanner;

public class Practice

{

    public static void heightEstimator(double momH, double dadH)
    {
        Scanner kb= new Scanner(System.in);
        System.out.println("Enter your Mothers Height in Feet: ");
        momH= kb.nextInt();
        System.out.println("Enter your Fathers Height in Feet: ");
        dadH= kb.nextInt();
        double w= (dadH+momH)/2;
        System.out.println("You will be "+ w+ "Ft.");       
    }

    public static int shoeSize(double x)
    {
        Scanner z= new Scanner(System.in);
        System.out.println("Enter your Fathers Heigh in Inches: ");
        x= z.nextInt();
        double y= x/6;
        System.out.println("Your shoe size will be: "+ y);
        return 0;           
    }
    public static void main(String[] args)
    {
        heightEstimator(0, 0);
        shoeSize(0);
    }


}

我不确定为什么我一直在我的代码中出现此错误。我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

momH = kb.nextInt();是错误的,因为datatytpe" momH"和#34;爸爸"和" x"是双数据类型,而不是整数。

*

  

您应该将nextInt()更改为nextDouble();

*