Skip to content

Instantly share code, notes, and snippets.

@shime
Created April 23, 2012 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shime/2469746 to your computer and use it in GitHub Desktop.
Save shime/2469746 to your computer and use it in GitHub Desktop.
replace every character at odd index with "&" in a string
class Nes
{
public static void main(String[] args) {
String a = "lastavice trče";
for (int i=0; i < a.length(); i++){
if (i % 2 != 0){
a = a.substring(0,i-1) + "&" + a.substring(i, a.length());
}
}
System.out.println(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment