所以我正在尝试第二个Java代码战争kata,但字符串格式化程序在我测试时返回正确的东西。这是卡塔:
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);
}
}
我的尝试:
public class HelloWorld{
public static void main(String []args){
Person p = new Person("bob");
System.out.println(p.greet("bobby"));
}
}
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);
}
}
它应该工作得很好,有什么不对?我正在做this site's kata,我不确定它需要什么。
答案 0 :(得分:1)
您已经颠倒了greet
方法中参数的顺序:
public String greet(String yourName) {
return String.format("Hi %s, my name is %s", yourName, name);
}