-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhoLikesIt.java
44 lines (39 loc) · 1.18 KB
/
WhoLikesIt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.smlnskgmail.jaman.codewarsjava.kyu6;
// https://www.codewars.com/kata/5266876b8f4bf2da9b000362/
public class WhoLikesIt {
private final String[] input;
public WhoLikesIt(String... input) {
this.input = input;
}
public String solution() {
switch (input.length) {
case 0:
return "no one likes this";
case 1:
return String.format(
"%s likes this",
input[0]
);
case 2:
return String.format(
"%s and %s like this",
input[0],
input[1]
);
case 3:
return String.format(
"%s, %s and %s like this",
input[0],
input[1],
input[2]
);
default:
return String.format(
"%s, %s and %s others like this",
input[0],
input[1],
input.length - 2
);
}
}
}