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 |
how many types of Inheritance?
Is vector synchronized in java?
What are the major advantages of internal iteration over external iteration?
How do I remove a character from a string in java?
What is the list interface?
Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?
What is an 8 bit word?
Is sizeof a keyword in java programming?
What is meant by serialisation and deserialisation?
how can u create the object with out new operator
How do you define a method?
What are operators and its types?