Returning string in java using 3 parameters

Posted by user2905118 on Stack Overflow See other posts from Stack Overflow or by user2905118
Published on 2013-10-22T03:23:56Z Indexed on 2013/10/22 3:54 UTC
Read the original article Hit count: 143

Filed under:

Need to write a method describePerson() that takes 3 parameters, a String giving a person’s name, a boolean indicating their gender (true for female, false for male), and an integer giving their age. The method should return a String formatted as in the following examples:

Lark is female. She is 2 years old. Or Jay is male. He is 1 year old.

I am not sure how to write it correctly (my code):

int describePerson(String name, boolean gender, int age) {
    String words="";
    if(gender==true)  return (name + "is "+gender+". "+"She is"+age+ "years old.);
    else
        return (name + "is "+gender+". "+"She is"+age+ "years old.);

} 

The outcome "year" and "years" is also differs, but i don't know how to make it correct..

© Stack Overflow or respective owner

Related posts about java