how to takes return sorted array from selection sort function
package function1;
import java.util.Scanner;
public class Chalengeofselectionsort {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int[] array = takesinput();
int[] sorted = selectionsort(array);
display(sorted);
}
// takes input function
public static int[] takesinput() {
//System.out.println("enter the size of array");
int n = scn.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
//System.out.println("enter the value for" + i + "index");
arr[i] = scn.nextInt();
}
return arr;
}
// selectionsort function
public static int[] selectionsort(int[] array) {
for (int counter = 0; counter < array.length - 1; counter++) {
int min = counter;
for (int j = counter + 1; j < array.length - 1; j++) {
if (array[j] < array[min]) {
min = j;
}
int temp = array[min];
array[min] = array[j];
array[j] = temp;
}
}
return array;
}
//display function
public static void display(int [] sorted) {
for(int i =0; i<sorted.length;i++) {
System.out.println(sorted[i]);
}
}
}
package function1;
import java.util.Scanner;
public class Chalengeofselectionsort {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int[] array = takesinput();
int[] sorted = selectionsort(array);
display(sorted);
}
// takes input function
public static int[] takesinput() {
//System.out.println("enter the size of array");
int n = scn.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
//System.out.println("enter the value for" + i + "index");
arr[i] = scn.nextInt();
}
return arr;
}
// selectionsort function
public static int[] selectionsort(int[] array) {
for (int counter = 0; counter < array.length - 1; counter++) {
int min = counter;
for (int j = counter + 1; j < array.length - 1; j++) {
if (array[j] < array[min]) {
min = j;
}
int temp = array[min];
array[min] = array[j];
array[j] = temp;
}
}
return array;
}
//display function
public static void display(int [] sorted) {
for(int i =0; i<sorted.length;i++) {
System.out.println(sorted[i]);
}
}
}