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
Are private methods final?
Can constructor be inherited?
Where are register variables stored?
What is a conditional statement explain with example?
What are heterogeneous objects?
What is the loop in java?
Explain about public and private access specifiers?
Which sorting algorithm is best in java?
Can we override static methods in java?
What is meant by method overriding?
What is class level lock ?
What do you mean by ternary operator in java?
Explain the concept of proper inheritance?
What are the legal parameters?
what is meant by HQL?