Im an AP computer science studen (we started two weeks ago so I dont know much). For homework we had this problem: " Write a program that will let you enter your gender (M or F) and your height in inches and will then tell you wether you are tall,medium or short. Men are tall if over 72 inches and short if under 66 inches. Girls are tall if over 66 inches and short if under 60 inches." The code I have so far is totally messed up. Anyhelp would be great appreciated. Thank you.

import java.io.*;
public class work
 
  {public static input in = new input();
    
public static void main(String[] args) throws IOException
{ int height;
  String gender;
System.out.println("Enter gender:");
gender = in.getString();
System.out.println("Enter height in inches:");
height = in.getInt();

if (gender==m && height>72)
System.out.println("You are tall");
if (gender==m && height>66)
System.out.println("You are medium");
else if (gender==m && height<67)
System.out.println("You are small");
}
 
   }

Can you explain what your problem is?
Do you get errors or is the output wrong?
Post the output with your questions or comments and show what it should output.

Comments on your coding style:
Don't have statements on the same line following a {
Put the statement on the next line and indent it 3-4 spaces.
Class names should start with uppercase letter.

Can you explain what your problem is?
Do you get errors or is the output wrong?
Post the output with your questions or comments and show what it should output.

Comments on your coding style:
Don't have statements on the same line following a {
Put the statement on the next line and indent it 3-4 spaces.
Class names should start with uppercase letter.

The error I am getting is at line 14 with the "m" it is saying: "cannot find symbol- variable m

where is the variable m defined? The compiler wants you to define ALL the variables that you use in the program so it knows how to work with them. It does different things with Strings and with integers etc. So you must tell the compiler what kind of variable m is.

If you want the m to be a String you must enclose it in "s: "m"

gender is a string use .equals (); put the "m" into quotes inside the brackets to compare the two strings

where is the variable m defined? The compiler wants you to define ALL the variables that you use in the program so it knows how to work with them. It does different things with Strings and with integers etc. So you must tell the compiler what kind of variable m is.

If you want the m to be a String you must enclose it in "s: "m"

im not trying to define m for anything i just want to make it: if "m" is input do this...

if "m" is input do this...

You left off the "s in your code.

You left off the "s in your code.

where? line number please.

The error I am getting is at line 14 with the "m" it is saying: "cannot find symbol- variable m

The error I am getting is at line 14 with the "m" it is saying: "cannot find symbol- variable m

yes thats same error im getting...but u said I left off an "s ...where?

Line 14

What NormR1 said was this line

if (gender==m && height>72)

change it to

if (gender=="m" && height>72)

and you need to update all other 3 more where gender==m is. You could also use

if (gender.equals("m") && height>72)

that will be safer in general but not in your case. But with this

if (gender.equalsIgnoreCase("m") && height>72)

will help you when someone enter "m" or "M" because they both are the same when their case are in-sensitive.

So i figured out the code now it works perfectly. Here is a copy of new code just for reference

import java.io.*;
public class work
 
  {public static input in = new input();
   
public static void main(String[] args) throws IOException
{
int height;
String gender;
System.out.println("Enter gender:");
gender = in.getString();
System.out.println("Enter height in inches:");
height = in.getInt();

if (gender.equals("m") && height>72)
System.out.println("You are tall");
else if (gender.equals("m") && height>66)
System.out.println("You are medium");
else if (gender.equals("m") && height<67)
System.out.println("You are small");

if (gender.equals("f") && height>66)
System.out.println("You are tall");
else if (gender.equals("f") && height>=61)
System.out.println("You are medium");
else if (gender.equals("f") && height<61)
System.out.println("You are small");
}
 
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.