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
What does string [] args mean?
Is upper case in java?
Can we create a constructor in abstract class?
What is bitwise complement?
How do you sort data in java?
Which object oriented concept is achieved by using overloading and overriding?
What is the structure of java?
What is lastindexof in java?
Name few java.lang classes introduced with java 8 ?
What is an off by one error in java?
When will you define a method as static?
How do you check if a string contains only numeric digits?
What is are packages?
How do you escape a string?
How objects are stored in java?