假设要输入一组数进行快速排序:
public static void main(String[] args) { Digui digui = new Digui(); System.out.println("请输入一行数字,用逗号隔开:"); Scanner scanner = new Scanner(System.in); String[] split = scanner.next().split(","); int[] a = new int[split.length]; for(int i=0;i<split.length;i++){ a[i] = Integer.parseInt(split[i]); } System.out.println("排序前:\n"+ Arrays.toString(a)); digui.quickSort(a, 0, a.length-1); System.out.println("排序后:\n" + Arrays.toString(a)); }
运行结果: