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

How do you check if two strings are equal in java?

0 Answers  


List the features of java programming language.

0 Answers  


Can sleep() method causes another thread to sleep?

0 Answers  


When finalize method is called?

3 Answers  


What is function and its uses?

0 Answers  


Explain listiterator and methods in listiterator?

0 Answers  


Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?

1 Answers   Rolta, TCS,


How do you compare values in java?

0 Answers  


what is the use of clone() in real time scenario?

2 Answers   Quinnox,


Difference between nested and inner classes ?

0 Answers  


Are there any tools available in java to create reports?

5 Answers  


what is diffrence between .NET and java?

2 Answers  


Categories