public class AbbreviateTwoWords { public static String abbrevName(String name) { return "%s.%s".formatted(name.charAt(0), name.charAt(name.indexOf(" ") + 1)); } }
- public class AbbreviateTwoWords {
- public static String abbrevName(String name) {
return name.replaceAll("[^A-Z\\s]","").replaceAll("\\s",".");- return "%s.%s".formatted(name.charAt(0), name.charAt(name.indexOf(" ") + 1));
- }
- }
public class Kumite {
public static boolean boolCheck(boolean[] bools) {
return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void test0True() {
boolean[] bools = new boolean[3];
assertEquals(false, Kumite.boolCheck(bools));
}
@Test
void test1True() {
boolean[] bools = new boolean[3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
bools[j] = false;
}
bools[i] = true;
assertEquals(false, Kumite.boolCheck(bools));
}
}
@Test
void test2True() {
boolean[] bools = new boolean[3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
bools[j] = true;
}
bools[i] = false;
assertEquals(true, Kumite.boolCheck(bools));
}
}
@Test
void test3True() {
boolean[] bools = new boolean[]{true, true, true};
assertEquals(true, Kumite.boolCheck(bools));
}
}