Programming Examples
Java program to arrange the sentence in alphabetical order of the words
Write a program to accept a sentence as input. The words in the string are to be separated by a blank. Each word must be in upper case. The sentence is terminated by either “.â€,â€!†or “?â€. Perform the following tasks:
(i) Obtain the length of the sentence (measured in words).
(ii) Arrange the sentence in alphabetical order of the words.
Example 1
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
LENGTH : 6
REARRANGED SENTENCE : INVENTION IS MOTHER NECESSITY OF THE
Example 2
INPUT: BE GOOD TO OTHERS.
OUTPUT:
LENGTH : 4
REARRANGED SENTENCE : BE GOOD OTHERS TO
Output