Click here to Skip to main content
16,007,760 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public class Person {
  String name;

    public Person(String personName) {
            name = personName;
    }

    public String greet(String yourName) {
            return String.format("Hi %s, my name is %s", name, yourName);
    }
}
Posted
Updated 4-Nov-15 9:13am
v3
Comments
Richard Deeming 4-Nov-15 15:10pm    
Click on the "Improve question" button and update your question with the missing details. Include a description of what the "expected value" is, and what value you're getting at the moment.

While you're at it, you might want to update your title so that it's not quite so rude. You're dealing with unpaid volunteers here; a terse demand that we correct your code isn't going to win you any friends.
veena15 4-Nov-15 15:18pm    
I found this code on www.codewars.com . In order to sign up , I have given two codes to be corrected. I have corrected the first question. This is the second question. Hope someone will help me.
Richard Deeming 4-Nov-15 15:40pm    
That's a better title, but you still haven't explained what the "expected value" is.
Richard Deeming 4-Nov-15 15:47pm    
Guessing based on the variables: is it that the names are the wrong way round? Do you just need to swap the order of the name and yourName arguments in the String.format call?
Afzaal Ahmad Zeeshan 4-Nov-15 15:30pm    
I can only say this is a bad coding design. Three different areas (or variables) for the same thing? Ok, name and personName can be left, but why yourName? Most programs are like this,


public String greet() {
return String.format("Hello %s!", name);
}


Where name is already present in the object instance. For more please refer to documentation, http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html.

1 solution

As mentioned in the comments, switch the variables in your String.Format. This is very easy to notice so I am unsure why you did not ask a question and why you are stuck on this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900