题目
调试sayHello函数
星舰企业在创建一个程序时遇到了一些问题,当他们上船时问候每个人。修复代码并使程序重新运行是您的工作!
输出示例:
Hello, Mr. Spock
待修改的代码:
public class GrassHopper {
public static String (String name) {
return "Hello, " name;
}
}
测试用例:
import java.util.Random;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class GrassHopperTest {
@Test
public void test1() {
assertEquals("Hello, Mr. Spock",
GrassHopper.sayHello("Mr. Spock"));
}
@Test
public void test2() {
assertEquals("Hello, Captain Kirk",
GrassHopper.sayHello("Captain Kirk"));
}
@Test
public void test3() {
assertEquals("Hello, Liutenant Uhura",
GrassHopper.sayHello("Liutenant Uhura"));
}
@Test
public void test4() {
assertEquals("Hello, Dr. McCoy",
GrassHopper.sayHello("Dr. McCoy"));
}
}
解题
public class GrassHopper {
public static String sayHello(String name) {
return "Hello, " + name;
}
}
后记
是最近做的8kyu简单了还是之前做的难了。