public class JSort { public static void main(String args[]) { char boxes[] = {'Z','Y','X','W','V','U','T','S','R','Q','P','O','N', 'M','L','K','J','I','H','G','F','E','D','C','B','A'}; for (int repeat=20000000; repeat>0; repeat--) { for (int lightestBoxNum=0; lightestBoxNum<25; lightestBoxNum++) { for (int compareBox=lightestBoxNum + 1; compareBox<26; compareBox++) { char leftWeight = boxes[lightestBoxNum]; char rightWeight = boxes[compareBox]; if ((repeat & 1) == 0) { if (rightWeight < leftWeight) { boxes[lightestBoxNum] = rightWeight; boxes[compareBox] = leftWeight; } } else { if (rightWeight > leftWeight) { boxes[lightestBoxNum] = rightWeight; boxes[compareBox] = leftWeight; } } } } } /*for (int i=0; i<26; i++) System.out.print(boxes[i]); System.out.println();*/ } }