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



if we give input as " hi how are you" then the output should be "uoy woh"...it..

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

Post New Answer

More Core Java Interview Questions

What does main method?

0 Answers  


Can we use different return types for methods when overridden?

0 Answers  


When is the arraystoreexception thrown?

0 Answers  


what is singleton in java?

0 Answers   IBS,


What is the tradeoff between using an unordered array versus an ordered array?

0 Answers  






Which is bigger double or float?

0 Answers  


What is audio clip interface? Name few methods of it ?

1 Answers  


What is constructor chaining in java?

0 Answers  


What is the difference between jvm and jre? What is an interface?

0 Answers  


Inorder to specify a container?s layout, which method is used?

1 Answers  


what is the use of abstract class and interface with example?

2 Answers   Cycore, DNS, Technoram,


Why only one Class is public in one file? Explain in details. Thanks in Advance.

12 Answers  


Categories