In: Computer Science
CODE IN JAVA:
import java.util.Scanner;
class WordDemo {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner sc = new
Scanner(System.in);
String arr[] = new String[5];
System.out.println("Enter 5
words:");
for(int i=0;i<5;i++) {
arr[i] =
sc.nextLine();
}
//arranging the words from high
length to low length using bubble sort
for(int i=0;i<5;i++) {
for(int
j=0;j<4;j++) {
if(arr[j].length()<arr[j+1].length()) {
String temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp ;
}
}
}
System.out.println("Now the words
in the order is:");
for(String str:arr)
System.out.print(str+" ");
}
}
OUTPUT:
