I want to convert every other letter in a string to capital. Say I have a string: "h3e5l!@lo461!28", I need to see if the character is a letter and then convert every other letter to capital. Here is my code right now but it doesn't work and I don't understand what to do to fix it.
public static void main(String[]args){
String a = "h3e5l!@lo461!28" ;
System.out.println(cap(a));
}
public static String cap(String a){
for(int i = 0; i< a.length(); i++){
if(Character.isLetter(a.charAt(i)) && i % 2 == 0){
a.charAt(i) = a.toUpperCase();
}
}
return a;
}