MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / sortFruits

Method sortFruits

Lecture 40/src/Main.java:2–16  ·  view source on GitHub ↗
(String[] fruits)

Source from the content-addressed store, hash-verified

1public 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"};

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected