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.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> al = new ArrayList<>();

		int x = 999;
		int y = 999;
		int cnt = 0;
		
		while(x != 0 || y != 0) {
			x = sc.nextInt();
			y = sc.nextInt();
			if(x == 0 && y == 0) {
				break;
			} else if(x < y) {
				cnt = cnt + 2;
				al.add(x);
				al.add(y);
			} else if(x > y) {
				cnt = cnt + 2;
				al.add(y);
				al.add(x);
			} else {
				cnt = cnt + 2;
				al.add(x);
				al.add(y);
			}
		}
		
		int i = 0;
		while(i < cnt) {
			System.out.println(al.get(i) + " " + al.get(i+1));
			i = i + 2;
		}
	
	}
}