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

Is alive method in java?

0 Answers  


What is a null point?

0 Answers  


What is the set interface in java programming?

0 Answers  


What are predicates in java 8?

0 Answers  


why we import both packages java.awt.*; and java.awt.event.*; as java.awt.*; can import all classes na. then what is the need of importing java.awt.event.*; ?

3 Answers  






How garbage collection is done in java?

0 Answers  


What is the difference between static and non-static variables in java programming?

0 Answers  


What language is java written?

0 Answers  


Why we can not force Garbage Collection?

7 Answers  


State two differences between C and Java.

0 Answers   Syntel, Visa,


What is a ternary operator in java? What is an interface?

0 Answers  


What is the use of static import ?

4 Answers   Rolta,


Categories