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
What is j2ee application?
What is jaap?
What is wildfly java?
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 ????
What is enterprise information system resource?
How many types of component events are in java?
I’m new to WebLogic Does anyone knows how to Deploy Application using
What are the four components of j2ee application?
Why frameworks are used in java?
How do I become a java developer?
What is full form of j2ee?
how to run servlet program between two computer through internet ?
What is j2ee tutorial?
What does the application client module contain?
How do you compile java?