Posts

Showing posts with the label arrange words based on length in java

Arrange Words ISC Computer Science 2020 Practical

Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The words are to be separated by a single blank space and are in uppercase. Perform the following tasks: (a) Check for the validity of the accepted sentence only for the terminating character. (b) Arrange the words in ascending order of their length. If two or more words have the same length, then sort them alphabetically. (c) Display the original sentence along with the converted sentence. Test your program for the following data and some random data: Example 1 : INPUT: AS YOU SOW SO SHALL YOU REAP. OUTPUT: AS YOU SOW SO SHALL YOU REAP. AS SO SOW YOU YOU REAP SHALL Example 2 : INPUT: SELF HELP IS THE BEST HELP. OUTPUT: SELF HELP IS THE BEST HELP. IS THE BEST HELP HELP SELF Example 3 : INPUT: BE KIND TO OTHERS. OUTPUT: BE KIND TO OTHERS. BE TO KIND OTHERS Example 4 : INPUT: NOTHING IS IMPOSSIBLE# OUTPUT: INVALID INPUT import java.util.Scanner; import java.util.StringToke...