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.
1
Expert's answer
2012-08-09T07:37:56-0400
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] + " ";
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment