java 代码战争:注册问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28585807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:51:31  来源:igfitidea点击:

Code wars: Sign up issue

java

提问by user1738642

Im very new to programming and I recently tried to sign up to code wars. It shows a number of problems, presumably before letting someone sign up.

我对编程很陌生,最近我尝试报名参加代码War。它显示了许多问题,大概是在让某人注册之前。

At the minute I'm stuck on this one:

此刻我被困在这个问题上:

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

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

说明 更正此代码,以便greet 函数返回预期值。

I can't for the life of me figure out what the problem is. I tried inputing the code into eclipse and there are no errors, so I'm not entirely sure what is required

我一生都无法弄清楚问题是什么。我尝试将代码输入 eclipse 并且没有错误,所以我不完全确定需要什么

回答by Ryanas

I think it 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 that the output is

所以输出是

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

嗨(人),我的名字是(不管你叫什么名字)

回答by sagar

Seriously, that was a waste of time. I had the same issue, there is nothing related to finding errors, it just wants to greet you. So just swap the arguments(name,yourName) in return statement.

说真的,那是浪费时间。我遇到了同样的问题,与查找错误无关,只是想向您致意。所以只需在 return 语句中交换 arguments(name,yourName) 即可。

回答by Senthilvel

The Answer Is : Justyou need two swap the variables in String.format().

答案是:只需要在 String.format() 中交换两个变量即可。

Question:

问题:

return String.format("Hi %s, my name is %s", name, yourName);

return String.format("嗨 %s,我的名字是 %s", name, yourName);

Answer :

回答 :

return String.format("Hi %s, my name is %s", yourName, name);

return String.format("嗨 %s,我的名字是 %s", yourName, 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);
           }
      }

回答by Chaklader

As it mentioned, the compiler expects a certain String as following,

正如它所提到的,编译器期望某个字符串如下,

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