标签:
4 2 1 3 4 5 5 4 3 2 1 0
1 2 3 4 1 4 3 2 5
import java.util.Arrays; import java.util.Scanner; public class Main50 { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { int n = input.nextInt(); if (n == 0) { break; } int [] array = new int[n]; for (int i = 0;i<n;i++) { array[i] = input.nextInt(); } int [] a = solove(array); } } private static int[] solove(int[] array) { int min = array[0]; int index = 0; for (int i = 0;i<array.length;i++) { if (array[i] < min) { min = array[i]; index = i; } } //交换这两个数字 if (index != 0) { int temp = array[0]; array[0] = array[index]; array[index] = temp; } System.out.print(array[0]+" "); for (int i = 1;i<array.length;i++) { System.out.print(array[i]+" "); } System.out.println(); return null; } }
标签:
原文地址:http://www.cnblogs.com/airycode/p/5504681.html