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 j2ee application?

721


What is jaap?

709


What is wildfly java?

657


I am newbie in J2EE & looking for strong basic behind each concept as, Why do we use private access specifier before each variable of type property bcoz ultimately to access it outside the class we use public method as getter & setter ? If we use getter & setter to access it outside the class so better we make variable as public so that it is easily available outside of the class... Please guide me why do we use as private ????

5441


What is enterprise information system resource?

702






How many types of component events are in java?

637


I’m new to WebLogic Does anyone knows how to Deploy Application using

1926


What are the four components of j2ee application?

746


Why frameworks are used in java?

644


How do I become a java developer?

674


What is full form of j2ee?

702


how to run servlet program between two computer through internet ?

2700


What is j2ee tutorial?

671


What does the application client module contain?

655


How do you compile java?

656