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

Can we execute a program without main?

758


What about main thread in java?

876


Can an interface be final?

776


What are jee technologies?

775


Explain about anonymous inner classes in java?

798


What are methods?

773


What is called module?

769


What is the final class?

752


What state is a thread in when it is executing?

736


What is object english?

830


Can we call the constructor of a class more than once for an object?

845


a thread is runnable, how does that work? : Java thread

699


What is lambda in java?

766


Can a source file contain more than one class declaration?

734


Why charat is used in java?

823