64 730
Assignments Done
99,3%
Successfully Done
In September 2018

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);
String
input = in.nextLine();
String [] splitted = input.toLowerCase().split("
");
int maxLength = 0;
for (int i = 0; i < splitted.length;
i++)
if (splitted[i].length() > maxLength)
maxLength =
splitted[i].length();
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);

System.out.println(output);
}
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions