Write a java program to get a string of words and print the numbers of each word count in descending order
Answer Posted / megha shetty
public class Inc {
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp;
String s="this is my way of doing it";
String s1[]=s.split(" ");
for(int j=1;j<=s1.length-1;j++)
for(int i=0;i<s1.length-j;i++)
{
if(s1[i].length()<s1[i+1].length())
{ temp=s1[i];
s1[i]=s1[i+1];
s1[i+1]=temp;
}
}
System.out.println("
new sorted array:
");
for(String i:s1)
System.out.println(i+" the length is "+i.length());
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why we used vector class?
What is string example?
What is an immutable class? How to create an immutable class?
What is the difference between private & public & friendly classes?
What is method overriding in java ?
what invokes a threads run() method? : Java thread
What is meant by structural programming?
What is basic syntax?
Explain purpose of sleep() method in java?
What is the function of compareto in java?
How do you declare a variable?
Can a method be overloaded based on different return type but same argument type?
What is a generic code?
Why is a string immutable?
How transient variable is different from volatile variable?