/* * QuadraticSort.java * */ import java.util.Scanner; public class QuadraticSort { public static void main (String[] args) { int i, j, tmp, length; int[] a; Scanner sc=new Scanner(System.in); System.out.println("Please input the length of array which you want to sort"); length=sc.nextInt(); a = new int[length]; /* input the elements of the array */ System.out.println("Please input the elements of array one by one"); for (i=0; i< length; i++) { a[i] = sc.nextInt(); } /* output the unsorted array */ System.out.print("The array is: "); for(i=0;i a[j]) { /* switch a[i] and a[j] */ tmp = a[i]; a[i] = a[j]; a[j] = tmp; } } } /* output the sorted array */ System.out.print("The sorted array is: "); for (i=0; i < length; i++) { System.out.print(a[i] +", "); } System.out.println(); } }