import java.util.Scanner;
public class DescendingWordSort {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] words = new String[40];
// Input 40 words
System.out.println("Enter 40 words:");
for (int i = 0; i < 40; i++) {
words[i] = scanner.nextLine();
}
// Selection sort in descending order
for (int i = 0; i < words.length - 1; i++) {
int maxIndex = i;
for (int j = i + 1; j < words.length; j++) {
if (words[j].compareTo(words[maxIndex]) > 0) {
maxIndex = j;
}
}
// Swap the found maximum element with the first element
String temp = words[maxIndex];
words[maxIndex] = words[i];
words[i] = temp;
}
// Print the sorted array
System.out.println("\nWords in descending order:");
for (String word : words) {
System.out.println(word);
}
scanner.close();
}
}