Answer:
See explaination
Explanation:
import java.util.Scanner;
public class SortArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter Size Of Array");
int size = sc.nextInt();
int[] arr = new int[size]; // creating array of size
read(arr); // calling read method
sort(arr); // calling sort method
print(arr); // calling print method
}
// method for read array
private static void read(int[] arr) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
System.out.println("Enter " + i + "th Position Element");
// read one by one element from console and store in array
arr[i] = sc.nextInt();
}
}
// method for sort array
private static void sort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
if (arr[i] < arr[j]) {
// Comparing one element with other if first element is greater than second then
// swap then each other place
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
// method for display array
private static void print(int[] arr) {
System.out.print("Your Array are: ");
// display element one by one
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + ",");
}
}
}
See attachment