3 ms·
My take (using switch expressions) private String generateGuessSentence(char candidate, int count) { return switch(count){ case 0 -> "T
by TrianguloY 2y ago
My take (using switch expressions)
private String generateGuessSentence(char candidate, int count) {
return switch(count){
case 0 -> "There are no " + candidate +"s";
case 1 -> "There is one " + candidate;
default -> "There are " + count + " " + candidate + "s";
};
}
And it would look even better with string templates...hopefully soon!
- TrianguloY 2y agoHey, wait, you can use String format with positional parameters... private static String generateGuessSentence(char candidate, int count) { return String.format(switch(count){ case 0 -> "There are no %1$ss"; case 1 -> "There is one %1$s"; default -> "There are %2$s %1$ss"; }, candidate, count); }