-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringManipulator.java
37 lines (30 loc) · 1002 Bytes
/
StringManipulator.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
public class StringManipulator {
public static void main(String[] args) {
System.out.println(sentenceReverse("Hey how you doin?"));
}
public static String sentenceReverse(final String theString) {
StringBuilder sb = new StringBuilder(128);
String[] words = theString.split(" ");
for (int i = words.length - 1; i >= 0; i--) {
sb.append(words[i]);
if (i != 0) sb.append(" ");
}
return sb.toString();
}
public int triplets(final int[] arr) {
int count = 0;
int length = arr.length -1;
for (int i = 0; i < length; i++) {
for (int j = i + 1; j < length; j++) {
for (int k = j + 1; k < length; k++ ) {
if (i < j && j % i == 0) {
if (j < k && k % j == 0) {
count++;
}
}
}
}
}
return count;
}
}