Code Wars: Registration Issue

Im very new to programming, and I recently tried registering for code wars. It shows a number of problems, presumably, before allowing someone to register.

The minute I got stuck on this:

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", yourName, name); } } 

Note Correct this code so that the greet function returns the expected value.

I can’t understand in my life what the problem is. I tried to enter the code in eclipse and there are no errors, so I'm not quite sure what is required

+6
source share
4 answers

I think he wants you to greet someone else.

 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); } } 

So the conclusion

Hi (person), my name (whatever your name)

+8
source
Seriously, it was a waste of time. I had the same problem, there is nothing related to finding errors, she just wants to welcome you. So just replace the arguments (name, yourName) in the return statement.
+5
source

Answer: Justyou need to swap the variables in String.format ().

Question:

return String.format ("Hello, ss, my name is% s", name , your name );

Answer:

return String.format ("Hello, ss, my name is% s", your name , name );

  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", yourName,name); } } 
+2
source

As already mentioned, the compiler expects the specific line to be next,

 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", "Kate", "Joe"); } } 
0
source

Source: https://habr.com/ru/post/982684/


All Articles