I am just starting out in Java, I have lots to learn. I get the following error code.
error:incompatible types
gender=keyboard.next();
required: char
found: String
Does this mean that I should have gender as a String?
import java.util.Scanner;
public class Height
{
public static void main (String[] args)
{
int inches, feet,mFeet, mInches, fFeet, fInches, cFeet, cInches;
int mHeight, fHeight, cHeight;
char gender;
Scanner keyboard=new Scanner (System.in);
System.out.println("Enter the child's gender (M or F):");
gender=keyboard.next();
if ((gender=="M")||(gender=="F"));
System.out.println("Error - Invalid gender");
System.out.println("Enter mothers height (feet):");
mFeet=keyboard.nextInt();
System.out.println("Enter the mothers height (inches):");
mInches=keyboard.nextInt();
System.out.println("Enter fathers height (feet):");
fFeet=keyboard.nextInt();
System.out.println("Enter the fathers height (inches):");
fInches=keyboard.nextInt();
//convert input form mother and father to inches and estimate the adult height of the child//
mHeight=(mFeet*12)+mInches;
fHeight=(fFeet*12)+fInches;
if (gender=M)
//male child formula//
cHeightmHeight*13/12)+fHeight)/2;
else
// female child formula//
cHeightfHeight*12/13)+mHeight)/2;
//turn child height into feet and inches//
System.out.println("The estimated adult height of this child is "
+ cHeight/12+" feet "
+cHeight%12+" inches.");
}
}