(String[] fruits)
| 1 | public class Main { |
| 2 | static void sortFruits(String[] fruits){ |
| 3 | int n = fruits.length; |
| 4 | for(int i = 0; i < n-1; i++){ |
| 5 | int min_index = i; |
| 6 | for(int j = i+1; j < n; j++){ |
| 7 | if(fruits[j].compareTo(fruits[min_index]) < 0){ |
| 8 | min_index = j; |
| 9 | } |
| 10 | } |
| 11 | // swap fruits[min_index], fruits[i] |
| 12 | String temp = fruits[i]; |
| 13 | fruits[i] = fruits[min_index]; |
| 14 | fruits[min_index] = temp; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | public static void main(String[] args) { |
| 19 | String[] fruits = {"kiwi", "apple", "papaya", "mango"}; |