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 Posted / 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 |
Post New Answer View All Answers
Is singleton a bad practice?
What is ‘has a’’ relationship in java?
Explain the difference between serializable and externalizable in java?
Explain the overview of UDP messaging.
What are the concepts of 'OOPS'?
What is stringreader?
What is meant by final class?
What is jvm? Why is java called the platform independent programming language?
What is meant by method?
When do you call copy constructor?
What is byte data type?
Can you sort a string in java?
What are methods and how are they defined?
What do you understand by access specifiers in Java?
Why volatile is used in java?