当前位置: 代码迷 >> 综合 >> exercism————TwoFer
  详细解决方案

exercism————TwoFer

热度:87   发布时间:2023-12-13 18:14:43.0

题目:

在这里插入图片描述

解法一:

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