this is a problem of scheduling. If there is no special constraints on the schedule, you can just follow a sequential schedule.
// try this :-) public class T { public static void main(String[] args) { String a = "ABCDEFG"; int len = a.length(); int first = 0,second = 1; do { System.out.println(""+a.charAt(first)+a.charAt(second)); first = (first+2) % len; second = (second+2) % len; } while(first != 0 &&second != 1); } }
If there is no special constraints on the schedule, you can just follow a sequential schedule.
public class T {
public static void main(String[] args) {
String a = "ABCDEFG";
int len = a.length();
int first = 0,second = 1;
do {
System.out.println(""+a.charAt(first)+a.charAt(second));
first = (first+2) % len; second = (second+2) % len;
} while(first != 0 &&second != 1);
}
}