Write a java program to get a string of words and print the numbers of each word count in descending order

Answer Posted / prash

class WordCount{

public List list;
public static void main(String[] args) {
System.out.println(args[0]);
List arr = Arrays.asList(args);
Iterator it = arr.iterator();
List l = new ArrayList();
while (it.hasNext()) {
String s = (String) it.next();
System.out.println(s);
l.add(s.length());
}
Collections.sort(l);
Collections.reverse(l);
}
}

Is This Answer Correct ?    8 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we have a method name same as class name in java?

837


What state is a thread in when it is executing?

741


What are the types of strings?

800


Is there any way to find whether software installed in the system is registered by just providing the .exe file? I have tried the following code but its just displaying the directory structure in the registry. Here the code : package com.msi.intaller; import java.util.Iterator; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RootKey; public class RegistryFinder { public static void main(String... args) throws Exception { RegistryKey.initialize(RegistryFinder.class.getResource("jRe gistryKey.dll").getFile()); RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\ODBC"); for (Iterator subkeys = key.subkeys(); subkeys.hasNext();) { RegistryKey subkey = subkeys.next(); System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". } } }

1568


Is the empty set a singleton?

737


What are inner classes or non static nested classes in java?

940


How to perform quicksort in java?

796


What do you understand by access specifiers in Java?

814


Can an arraylist be empty?

799


What is replacefirst in java?

792


What is the difference between state-based unit testing and interaction-based unit testing?

740


What is meant by local variable and instance variable?

833


Explain parallel processing in java8?

919


What is java util collection?

779


Is it possible to override the main method?

754