Java tutorial
//package com.java2s; public class Main { private static String recoverIndex(String strCode) { char[] chars = strCode.toCharArray(); char temp; temp = chars[0]; chars[0] = chars[chars.length - 1]; chars[chars.length - 1] = temp; for (int i = 0; i < chars.length; i++) { if (i != 0 && i % 2 == 0) { temp = chars[i - 1]; chars[i - 1] = chars[i]; chars[i] = temp; } } return new String(chars); } }