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

Why arraylist is used in java?

0 Answers  


When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?

0 Answers  


Difference between canvas class & graphics class?

1 Answers  


Is minecraft java edition free?

0 Answers  


How do you add an element to a hashset in java?

0 Answers  






What is the epoch date?

0 Answers  


watz the difference between abstract class and interface? Which one u ill choose as a designer?

1 Answers   Sonata,


What is an abstract class and abstract method?

5 Answers  


What are the two major components of JDBC?

5 Answers   CMC, Mind Tree,


what is the difference between thread and runnable types? : Java thread

0 Answers  


How do you check if a string is lexicographically in java?

0 Answers  


How will you serialize a singleton class without violating singleton pattern?

0 Answers  


Categories