Question: Problem 4 Difficulty: EASY Problem Statement: Write a Java program to create an interface Sortable with a method sort ( int [ ] array )

Problem 4
Difficulty: EASY
Problem Statement:
Write a Java program to create an interface Sortable with a method sort (int[] array)
that sorts an array of integers in descending order. Create two classes QuickSort and
MergeSort that implement the Sortable interface and provide their own
implementations of the sort() method.
Code Structure
Use the following code snippet in the Main class. Do not edit the Main class. Define all
the other required classes, interface(s) and methods as required.
public class Main {
public static void main(String[] args){
// Take input for integer array nums
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); //size of array
int[] nums = new int[n];
for (int i =0; i < n; i++){
nums[i]= scanner.nextInt();
}
scanner.close();
// Create an instance of quickSort and perform sorting
Sortable quickSort = new QuickSort();
quickSort.sort(arr);
// Print the sorted array using Quick Sort
printArray(arr);
// Create an instance of MergeSort
Sortable mergeSort = new MergeSort();
mergeSort.sort(arr);
// Print the sorted array using Merge Sort
printArray(arr);
}
// Method to print the elements of an array
private static void printArray(int[] arr){
for (int num : arr){
System.out.print(num +"");
}
System.out.println();
}
}
Input format
First line takes the length of the array. Second line contains the elements of the array
separated by space.
5
142763
Output format
764321
764321
Sample Test Cases
Input:
5
142763
Output:
764321
764321
please solve this and please give full code with correct output and whenn i run it it should show correct output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!