根据 parents 输入查找 child 的高度。 Java
Finding the height of a child based on the parents input. Java
好的,所以我一直在尝试在 java 中编写一个程序,以根据 feet/inches 中的 parents 高度计算 child 的高度, ans 根据用户输入的性别估计答案。不过,我已经为此困惑了几个小时。似乎我没有尝试做正确的计算。我是 java 的新手,第 2 周..我觉得这应该很容易?也许我从中得到的比需要的多?
添加了我的程序完成后的外观图片。
(( Example of how the output needs to look. ))
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;
}
将 heightmom 和 heightdad 分成英尺和英寸。
使用双打来存储您的 MaleChildh 和 FemaleChildh。
更正单词 'estimaed'.
的拼写错误
编辑:看看你是否理解这段代码,然后将英寸部分添加到 child 的高度。
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String userChoice;
int heightMomFt, heightMomIn, heightDadFt, heightDadIn, genderChild;
double FemaleChildhFt, MaleChildhFt, FemaleChildhIn, MaleChildhIn;
while (true) {
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.");
heightMomFt = scan.nextInt();
heightMomIn = scan.nextInt();
System.out.println("Enter the height in feet, then the height in inches of the dad.");
heightDadFt = scan.nextInt();
heightDadIn = scan.nextInt();
MaleChildhFt = (heightMomFt * 13 / 12 + heightDadFt) / 2;
FemaleChildhFt = (heightDadFt + 12 / 13 + heightMomFt) / 2;
if (genderChild == 1)
System.out.println(("Your future child is estimated to grow to") + FemaleChildhFt);
if (genderChild == 0)
System.out.println(("Your future child is estimated to grow to") + MaleChildhFt);
System.out.println("Enter 'Y' to run again, anything else to exit.");
userChoice = scan.next();
if (userChoice.equals("Y"))
System.out.println("Continuing...");
else
break;
}
}
好的,所以我一直在尝试在 java 中编写一个程序,以根据 feet/inches 中的 parents 高度计算 child 的高度, ans 根据用户输入的性别估计答案。不过,我已经为此困惑了几个小时。似乎我没有尝试做正确的计算。我是 java 的新手,第 2 周..我觉得这应该很容易?也许我从中得到的比需要的多?
添加了我的程序完成后的外观图片。
(( Example of how the output needs to look. ))
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;
}
将 heightmom 和 heightdad 分成英尺和英寸。 使用双打来存储您的 MaleChildh 和 FemaleChildh。 更正单词 'estimaed'.
的拼写错误编辑:看看你是否理解这段代码,然后将英寸部分添加到 child 的高度。
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String userChoice;
int heightMomFt, heightMomIn, heightDadFt, heightDadIn, genderChild;
double FemaleChildhFt, MaleChildhFt, FemaleChildhIn, MaleChildhIn;
while (true) {
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.");
heightMomFt = scan.nextInt();
heightMomIn = scan.nextInt();
System.out.println("Enter the height in feet, then the height in inches of the dad.");
heightDadFt = scan.nextInt();
heightDadIn = scan.nextInt();
MaleChildhFt = (heightMomFt * 13 / 12 + heightDadFt) / 2;
FemaleChildhFt = (heightDadFt + 12 / 13 + heightMomFt) / 2;
if (genderChild == 1)
System.out.println(("Your future child is estimated to grow to") + FemaleChildhFt);
if (genderChild == 0)
System.out.println(("Your future child is estimated to grow to") + MaleChildhFt);
System.out.println("Enter 'Y' to run again, anything else to exit.");
userChoice = scan.next();
if (userChoice.equals("Y"))
System.out.println("Continuing...");
else
break;
}
}