Question: Problem 4 Difficulty: EASY Problem Statement: Write a Java program to create an interface Sortable with a method sort ( int [ ] array )
Problem
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, interfaces and methods as required.
public class Main
public static void mainString args
Take input for integer array nums
Scanner scanner new ScannerSystemin;
int n scanner.nextInt; size of array
int nums new intn;
for int i ; i n; i
numsi scanner.nextInt;
scanner.close;
Create an instance of quickSort and perform sorting
Sortable quickSort new QuickSort;
quickSort.sortarr;
Print the sorted array using Quick Sort
printArrayarr;
Create an instance of MergeSort
Sortable mergeSort new MergeSort;
mergeSort.sortarr;
Print the sorted array using Merge Sort
printArrayarr;
Method to print the elements of an array
private static void printArrayint arr
for int num : arr
System.out.printnum ;
System.out.println;
Input format
First line takes the length of the array. Second line contains the elements of the array
separated by space.
Output format
Sample Test Cases
Input:
Output:
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
