Question: import java.util.Scanner; public class array5j { public static void main(String[] args) { int a[] = new int[10]; // declares array a with 10 cells int
import java.util.Scanner; public class array5j { public static void main(String[] args) { int a[] = new int[10]; // declares array a with 10 cells int size = 7; // this is number of elements we'll have in the array a.
InputArray(a,size);
System.out.println("the sorted array is:"); int sorted[] = new int[10]; sorted = BubbleSort(a,size); OutputArray(sorted,size);
} // end of main program
public static void InputArray(int x[], int size) { Scanner input = new Scanner(System.in); int i; System.out.println ( "Enter " + size + "data: "); for (i=0; i public static void OutputArray(String x[], int size) { System.out.println("The array is:"); for (int i=0; i public static int[] reverse(int[] x, int size) { String[] result = new String[x.length]; for (int i=0; i<=size-1; i++){ result[i] = x[size-i-1]; } return result; } } Use this program and change it so that it will take a String array and sort it in anti-alphabetical order. Use compareTo or compareToIgnoreCase for the String type. Ex. input: dog lazy the output: the lazy dog
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
