Sorting arrays in method and returning to main method
Read an array of 5 integer values in the main method. Create a separate
function that will sort the array and return the array back to the main
method and print it there.
So far I have done:
import java.util.*;
public class arraysort {
public static void main(String[]args) {
Scanner in = new Scanner (System.in);
System.out.println("Enter 5 integers: ");
int [] x = new int [5];
for (int i=0; i<5; i++) {
x[i] = in.nextInt();
}
}
public static int sortarray(int [] value) {
int max = value[0];
for (int i = 1; i < value.length; i++) {
//I am not sure after this point
//I just did the rest
int [] y = new int [5];
Scanner in = new Scanner (System.in);
value[i] = in.nextInt();
Arrays.sort(y);
System.out.println(y);
}
}
}
No comments:
Post a Comment