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 map sorted in java?
What is the main purpose of serialization in java?
What is the do while loop syntax?
What modifiers may be used with an inner class that is a member of an outer class in java programming?
Is int primitive data type?
Describe string intern() methodology
What are data types in oop?
What is the multi-catch block in java?
What do you understand by abstract classes?
Difference between character constant and string constant in java ?
Where are variables stored?
What is the difference between preparedstatement and statement in java?
What is passing value java?
State the difference between strings and arrays.
How does arraylist work in java?