76 309
Assignments Done
Successfully Done
In May 2019

Answer to Question #12606 in Java | JSP | JSF for Richa Prasad

Question #12606
Write a programme to enter a sentence ;read the entered sentence which terminates with a full stop.the words are to be seperated with a single blank space and are in lower case.arrange the words contained in the sentence according to the length of the word in ascending order.if two words are of same length then the word occuring first in the entered sentence should come first.both input and output sentence must begi with upper case.
Expert's answer
import java.util.Scanner;

public class q12606 {
public static void
main(String args[]) {
Scanner in = new Scanner(System.in);
input = in.nextLine();
String [] splitted = input.toLowerCase().split("
int maxLength = 0;
for (int i = 0; i < splitted.length;
if (splitted[i].length() > maxLength)
maxLength =
String output = "";
for (int i = 1; i <=
maxLength; i++)
for (int j = 0; j < splitted.length; j++)

if (splitted[j].length() == i)
output += splitted[j] + " ";

output = Character.toUpperCase(output.charAt(0)) + output.substring(1);


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions