-
Notifications
You must be signed in to change notification settings - Fork 13
/
RomanNumeralTestI_4_red.java
37 lines (32 loc) · 1.07 KB
/
RomanNumeralTestI_4_red.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
package com.cj.interview.preparation;
public class RomanNumeralTestI_4_red {
public static void main(String[] args) {
new RomanNumeralTestI_4_red().run();
}
private void run() {
test(1, "I");
test(2, "II");
test(3, "III");
test(4, "IV");
}
private String romanNumeral(int value) {
return repeatI(value);
}
private String repeatI(int times) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < times; i++) {
stringBuilder.append("I");
}
return stringBuilder.toString();
}
private void test(int number, String expected) {
String actual = romanNumeral(number);
if (expected.equals(actual)) {
System.out.println(String.format("SUCCESS: %d -> %s", number, expected));
} else {
System.out.println(String.format("FAILURE: %d", number));
System.out.println(String.format(" actual : %s", actual));
System.out.println(String.format(" expected: %s", expected));
}
}
}