blackdiamondx :
I am trying to print every 3rd character of a string so an example would be: 123456
returns 36
But my code below returns 14
public String getEveryThird() {
String newString = "";
for (int i = 0; i < string.length(); i++) {
if (i % 3 == 0) {
newString += (string.charAt(i));
}
}
return newString;
}
Uladzislau Kaminski :
Good try. The only problem is you choose the wrong remainder of the division since elements start from 0.
Try this condition:
if (i % 3 == 2)