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 should a junior java developer know?
What is repaint in java?
What is a java applet?
What is build tool in java?
Why java is oop language?
What is authorization constraint?
What are the advanced technologies in java?
What is data?
what is direct link to download swing ebook,applet,ejb,core java
what is meant by proxy server
How does j2ee application work?
What is gridlayout in java?
What is filter chain?
What is enterprise information system?
How will you explain load() and get() methods?