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

What does string [] args mean?

629


Is upper case in java?

635


Can we create a constructor in abstract class?

659


What is bitwise complement?

601


How do you sort data in java?

630






Which object oriented concept is achieved by using overloading and overriding?

661


What is the structure of java?

614


What is lastindexof in java?

636


Name few java.lang classes introduced with java 8 ?

622


What is an off by one error in java?

586


When will you define a method as static?

666


How do you check if a string contains only numeric digits?

732


What is are packages?

679


How do you escape a string?

602


How objects are stored in java?

634