

public class SortEmArray {
	private int i;
	private int aux;
	private boolean ordenado;
	public int[] theArray;


	void addItens(String[] entrada) {

		System.out.println("Adicionando itens: ");
		theArray = new int[entrada.length];
		for (i = 0; i < entrada.length; i++) {
			theArray[i] = Integer.parseInt(entrada[i]);
			System.out.print(theArray[i] + " ");
		}
		System.out.println("\n");
	}


	void arrangeArray() {

		ordenado = false;
		while (ordenado != true) {
			ordenado = true;
			for (i = 0; i < theArray.length; i++) {
				if (i+1 < theArray.length && theArray[i] > theArray[i+1]) {
					ordenado = false;
					aux = theArray[i+1];
					theArray[i+1] = theArray[i];
					theArray[i] = aux;
				}
			}
		}
	}


	void showArray() {

		System.out.println("Array apos o Sort: ");
		for ( i = 0; i < theArray.length; i++) {
			System.out.print(theArray[i] + " ");
		}
		System.out.println("\n");
	}


	public static void main(String[] args) {

		if (args.length == 0) {
			System.out.println("Utilizacao: java SortEmArray 3 2 1");
			System.out.println("Resultado : 1 2 3");
		} else {
			SortEmArray vet = new SortEmArray();
			vet.addItens(args);
			vet.arrangeArray();
			vet.showArray();
		}
	}


}





