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


Please Help Members By Posting Answers For Below Questions

What are the steps involved to create a bean?

917


How can you handle java exceptions?

765


What is regex used for?

785


Explain about sets?

787


Explain about collection interface in java?

795


Give some features of interface?

850


Can constructor be protected in java?

748


What is the difference between static binding and dynamic binding?

845


What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?

799


What is instance example?

753


What is token in java?

804


What is method reference?

757


Can I learn java without any programming experience?

817


What are different types of control structures?

749


Can we serialize static variables in java?

888