if we give input as " hi how are you" then the output
should be "uoy woh"...it should skip odd words in the input
and should reverse even words from the end of string...can
anyone help me to write this program in java
Answer / nagesh
package test;
public class TestClass {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer("hi how
are you");
String input = sb.reverse().toString();
String output = "";
String[] stInput =input.split(" ");
for(int i=0;i<stInput.length;i++)
{
if(i%2==0)
{
if(i==0)
{
output = stInput[i];
}
else
{
output = output + " "+
stInput[i];
}
}
}
System.out.println("Output String is =="+output);
}
}
| Is This Answer Correct ? | 6 Yes | 0 No |
What is classpath?
Diff between C++ and java?
What primitive Java types? Howmany are they and what are their names?
What are the concepts of 'OOPS'?
What do you mean by composition in java?
What is the default size of set in java?
State one difference between a template class and class template.
Is empty string in java?
What is difference between string and new string?
What is method overloading and method overriding?
What is the size of string?
Explain role of constructor in a java application?