import jeliot.io.*; import java.util.*; public class MyClass { public static voi
ID: 3615348 • Letter: I
Question
import jeliot.io.*;
import java.util.*;
public class MyClass
{
public static void main(String[] args)
{
Scanner Kybd = new Scanner(System.in);
System.out.println("Input gender: ");
String gender = Kybd.next();
System.out.println("Height of mother in inches:");
double Hmother = Kybd.nextDouble();
System.out.println("Height of father in inches:");
double Hfather = Kybd.nextDouble();
if (gender.equals("male"))
{
System.out.println("Height of the child ininches is: " + ((Hmother * ((double)13/(double)12)) +Hfather)/2);
}
if (gender.equals("female"))
{
System.out.println("Height of the child ininches is: " + ((Hfather * ((double)12/(double)13)) +Hmother)/2);
}
}
}
Explanation / Answer
import java.util.*;
public class untitled {
public static void main(String[]args)
{int Hmother,Hfather;
String gender;
Scanner Kybd = new Scanner(System.in);
System.out.println("Input gender(none to exit):");
gender = Kybd.next();
while(gender.compareTo("none")!=0)
{ System.out.println("Height of mother in inches: ");
Hmother = Kybd.nextInt();
System.out.println("Height of father in inches: ");
Hfather = Kybd.nextInt();
if(gender.compareTo("male")==0)
System.out.println("Height of the child in inches is: " + ((Hmother* ((double)13/(double)12)) + Hfather)/2);
else
System.out.println("Height of the child in inches is: " + ((Hfather* ((double)12/(double)13)) + Hmother)/2);
System.out.println("Input gender(none to exit): ");
gender =Kybd.next();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.