Interview Question
Country: United States
If I understood your statement correct, starting 2 alphabet and every 3rd occurrence should be upper case.
ex: abcdefghij -> aBcdEfgHij
String str = "abcdefghij";
for(int i = 1; i < str.length(); i=i+3) {
str = str.replace(str.charAt(i), Character.toUpperCase(str.charAt(i)));
}
System.out.println(str);
If I understand correctly, the program should do the following:
1) preserve first character as-is (since the change in case is happening starting after 2nd character)
2) all characters after the second character should be lower case EXCEPT every 3rd character
ex: abcdefghij -> aBcdEfgHij
ABCDEFGHIJ -> ABcdEfgHij
aBCDEFGHIJ -> aBcdEfgHij
- Fahimeh.Fakour February 21, 2018