-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlternateCapitalization.java
33 lines (27 loc) · 1.11 KB
/
AlternateCapitalization.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
package com.smlnskgmail.jaman.codewarsjava.kyu7;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// https://www.codewars.com/kata/59cfc000aeb2844d16000075
public class AlternateCapitalization {
private final String input;
public AlternateCapitalization(String input) {
this.input = input;
}
public String[] solution() {
String capitalization = IntStream
.range(0, input.length())
.mapToObj(value -> {
String letter = String.valueOf(input.charAt(value));
return value % 2 == 0 ? letter.toUpperCase() : letter;
})
.collect(Collectors.joining());
String alternateCapitalization = IntStream
.range(0, input.length())
.mapToObj(value -> {
String letter = String.valueOf(input.charAt(value));
return value % 2 != 0 ? letter.toUpperCase() : letter;
})
.collect(Collectors.joining());
return new String[]{capitalization, alternateCapitalization};
}
}