i need to output the unsorted array as well as the sorted array...the sorted array works but i can not get the unsorted array to work. please help!
package Lab7; import java.util.Scanner; public class lab10 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to the insertion sorter!"); System.out.println("Please enter the number of values you would like to sort"); int size = keyboard.nextInt(); int[] a = new int[size]; //populate the array for(int i=0;i<a.length;i++) { System.out.println("Enter the number at position "+i); a[i] = keyboard.nextInt(); } //Selection sort! for(int i=0;i<a.length;i++) { int smallestIndex = i; for(int j=i;j<a.length;j++) { //Find the index of the next smallest value if(a[j]<a[smallestIndex]) { smallestIndex = j; } } if(smallestIndex != i)//Swap the values { int temp = a[i]; a[i] = a[smallestIndex]; a[smallestIndex] = temp; } } //Print out the unsorted and sorted array System.out.println("The unsorted array is "); for(int i=0;i<a.length;i++) { System.out.print(a[i]); } System.out.println("\nThe sorted array is "); for(int i=0;i<a.length;i++) { System.out.print(a[i]+" "); } } }