Problem:
Swapping Two Numbers

Write a program which reads two integers x and y, and prints them in ascending order.

Input

The input consists of multiple datasets. Each dataset consists of two integers x and y separated by a single space.

The input ends with two 0 (when both x and y are zero). Your program should not process for these terminal symbols.

Output

For each dataset, print x and y in ascending order in a line. Put a single space between x and y.

Constraints

0 ≤ x, y ≤ 10000

the number of datasets ≤ 3000

Sample Input

3 2
2 2
5 3
0 0

Sample Output

2 3
2 2
3 5

Solution in JAVA (judge verdict: Accepted)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) throws Exception {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		ArrayList<String> list1 = new ArrayList<String>();
		int[] list2 = new int[3001];
		int[] list3 = new int[3001];
		int i = 0;
		while (true) {
			list1.add(br.readLine());

			list2[i] = Integer.parseInt(SubStringStart(list1.get(i)));//???????????°???
			list3[i] = Integer.parseInt(SubStringEnd(list1.get(i)));//????°??????°???
			if (list2[i] == 0 && list3[i] == 0) {
				for (int k = 0; k < list1.size(); k++) {
					if (list2[k] > list3[k]) {
						System.out.println(list3[k] + " " + list2[k]);
					} else if (list2[k] < list3[k]) {
						System.out.println(list2[k] + " " + list3[k]);
					} else if (list2[k] == list3[k] && list2[k] != 0 && list3[k] != 0) {
						System.out.println(list2[k] + " " + list3[k]);
					}
				}
				break;
			}
			i = i + 1;
		}
	}

	public static String SubStringStart(String str) {
		int index = str.indexOf(" ");
		return (str.substring(0, index));
	}

	public static String SubStringEnd(String str) {
		int index = str.indexOf(" ");
		return (str.substring(index + 1));
	}
}
//class Main {
//	public static void main(String[] args) throws Exception {
//		InputStreamReader is = new InputStreamReader(System.in);
//		BufferedReader br = new BufferedReader(is);
//
//		String[] list1 = new String[3001];
//		int[] list2 = new int[3001];
//		int[] list3 = new int[3001];
//		int i = 0;
//		while (true) {
//			list1[i] = br.readLine();
//
//			list2[i] = Integer.parseInt(SubStringStart(list1[i]));//???????????°???
//			list3[i] = Integer.parseInt(SubStringEnd(list1[i]));//????°??????°???
//			if (list2[i] == 0 || list3[i] == 0) {
//				for (int k = 0; k < list1.length; k++) {
//					if (list2[k] > list3[k]) {
//						System.out.println(list3[k] + " " + list2[k]);
//					} else if(list2[k] < list3[k]){
//						System.out.println(list2[k] + " " + list3[k]);
//					}else if(list2[k] == list3[k]|| list2[k]!=0|| list3[k]!=0){
//						System.out.println(list2[k] + " " + list3[k]);
//					}
//				}
//				break;
//			}
//			i = i + 1;
//		}
//	}
//
//	public static String SubStringStart(String str) {
//		int index = str.indexOf(" ");
//		return (str.substring(0, index));
//	}
//
//	public static String SubStringEnd(String str) {
//		int index = str.indexOf(" ");
//		return (str.substring(index + 1));
//	}
//}