好的,所以我一直在尝试用java编写一个程序来根据父母的身高(英尺/英寸)计算孩子的身高,并根据用户输入的性别来估计答案。不过,我已经为此困扰了好几个小时。似乎我没有尝试做正确的计算。我是java新手,第2周..我觉得这应该很容易?也许我从中得到的比它需要的更多?
添加了我的程序完成后的外观图片。
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String userChoice;
int heightMom, heightDad, FemaleChildh, MaleChildh, genderChild;
System.out.println("Enter the gender of your future child. Use 1 for female,
0 for male.");
genderChild = scan.nextInt();
System.out.println("Enter the height in feet, then the height in inches of
the mom.");
heightMom = scan.nextInt();
System.out.println("Enter the height in feet, then the height in inches of
the dad.");
heightDad = scan.nextInt();
MaleChildh = (heightMom*13/12 + heightDad)/2;
FemaleChildh = (heightDad+12/13 + heightMom)/2;
if (genderChild.equals(1))
System.out.println(("Your future child is estimated to grow
to")+FemaleChildh);
if (genderChild.equals(0))
System.out.println(("Your future child is estimaed to grow to")+MaleChildh);
System.out.println("Enter 'Y' to run again, anything else to exit.");
userChoice = scan.next();
if (userChoice.equals("Y"))
System.out.println("Continuing...");
else if (userChoice.equals(""))
break;
}