Error, what did I do wrong?

I am a new learner and today I take the Java 1 Clean Coding: episode 3 Creating Methods. I write the exact the same code in the video, but it shows error in the last return line of firstName and lastName. The error says parameter firstName and lastName never used.

public class Practice {
public static void practice (String[] args) {

    String message = greetUser("Mosh", "Hamedani");
}
    public static String greetUser (String firstName, String lastName);
    return "Hello" + firstName + " " + lastName;
    }

You ended the declaration of your greetUser method with a semicolon. Instead you should enclose the method body in curly braces.

Thx, yes I change it in curly braces. Now it only shows error firstName in the last return line as" can not resolve symbol firstName. The lastName has no error .
public class Practice {
public static void practice(String[] args) {

    String message = greetUser("Mosh", "Hamedani");
}

public static String greetUser(String firstname, String lastName) {
    return "Hello" + firstName + " " + lastName;
}

}

Pay attention to casing. You named the parameter firstname (lower case n) while you wrote firstName in the return statement.

1 Like

Got it. Thank you very much!