Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java. Complete this code so that it prints the letters from the char array unord

ID: 3782132 • Letter: J

Question

java.

Complete this code so that it prints the letters from the char array unorderedLetter in decreasing order:

1 public class ReversesortDemo public static void main St ring[] args char unordered Letters unordered Letters new char 'm', 'z', 'a', 'u'li eversesort (unordered etters for (int i i unorderedLetters ngth itt system. out .print (unorderedLetters [i]) 10 methode that sorts a char array into its reverse alphabetical order 11 public static void reversesort(charl] values 12 //your code here 13 14 15 16)

Explanation / Answer

ReverseSortDemo.java

public class ReverseSortDemo {

   public static void main(String[] args) {
       //Declaring a character Array
       char[] unorderedLetters;
       unorderedLetters=new char[]{'b','m','z','a','u'};
      
       //Calling the method by passing the array as argument
       reverseSort(unorderedLetters);
      
       //This for loop will display the elements in the array
       for(int i=0;i<unorderedLetters.length;i++)
           System.out.println(unorderedLetters[i]);

   }

   //This method will sort the characters in the reverse order
   private static void reverseSort(char[] unorderedLetters) {
       char temp;
      
       //This nested for loop will sort the character array elements in reverse order
       for (int i = 0; i < unorderedLetters.length; i++)
   {
   for (int j = i + 1; j < unorderedLetters.length; j++)
   {
   if (unorderedLetters[i] < unorderedLetters[j])
   {
   temp = unorderedLetters[i];
   unorderedLetters[i] = unorderedLetters[j];
   unorderedLetters[j] = temp;
   }
   }
   }
      
   }

}

________________________

Output:

z
u
m
b
a

______________Thank You