题目:
解法一:
public class TwoFer {
String twoFerTest(String name) {
return name == null ? "One for you,one for me" : "One for " + name + ",one for me";}
}
解法二:
import java.util.Optional;class Twofer {
static String twofer(String name) {
return String.format("One for %s, one for me.",Optional.ofNullable(name).orElse("you"));}
}
解法三:
public class Twofer {
public String twofer(String name) {
return String.format("One for %s, one for me.", name==null ? "you" : name);}
}