write a program, when a statement is entered, it should
display in reverse order.
Ex: Statement is "I am writing program in reverse order".
Output should be like "order reverse in program writing am I".

Answer Posted / abhinaw kumar

package com.test;

public class ReverseString {

public static String reverse(String sentence){
String[] temp=sentence.split(" ");
StringBuffer sb = new StringBuffer();
for(int i=temp.length-1;i>=0;i--){
sb.append(temp[i]+" ");
}
sentence = sb.toString();
return sentence;
}

public static void main(String[] args) {
String sentence="I am writing program in reverse order";
String revString = reverse(sentence);
System.out.println(revString);

}
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is core java and j2ee?

581


What are the topics in j2ee?

594


What is java listener?

576


Enlist the technologies embraced in j2ee?

590


Which java technology is in demand?

550






What is data?

613


Is a relationship java?

567


What is the best java course?

581


What is component in java with example?

565


explain the technologies that j2ee platform provides for developing components.

558


What is j2ee api?

616


What is context root?

628


What is group?

650


What is the preferred size of a component in java?

524


Which software is used for java?

548