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 actionform?
What is use of final keyword in java?
What is java actionlistener?
What is client-certificate authentication?
What are the four components of j2ee application?
Why java is oop language?
Where can I find java developers?
What is java api for xml processing (jaxp)?
What is a web container in j2ee?
What is cmp in j2ee?
What is initialization parameter?
What should a junior java developer know?
what is direct link to download swing ebook,applet,ejb,core java
What is javaserver pages (jsp)?
What do you mean by the component contract?