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

Hi Friends. I want complete technical flow of j2ee project with following technologies. jsp , servlet , Struts , Hibernate , (should follow mvc-2 design pattern) . with DAO ,DTO SERVICE layers .

4403


What is difference between j2ee and java?

498


What is application client container?

527


What are the differences between Ear, Jar and War files? Under what circumstances should we use each one?

527


What is callback methods?

534






Can I run seam in a j2ee environment?

491


What are java front end tools?

507


What is a j2ee component?

516


How does event listener work in java?

472


What are the advanced technologies in java?

481


What is a java application client?

525


What is javamail?

529


What is mean by j2ee?

480


Enlist the technologies embraced in j2ee?

529


What are the main components of the j2ee application?

482