Answer Posted / anjani kumar jha
import java.util.*;
public class StringReverseWord {
private static void doStringReverseWord() {
String a = "Anjani ...................Kumar Jha";
Stack stack = new Stack();
// this statement will break the string into the
words which are separated by space.
StringTokenizer tempStringTokenizer = new
StringTokenizer(a);
// push all the words to the stack one by one
while (tempStringTokenizer.hasMoreTokens()) {
stack.push(tempStringTokenizer.nextElement());
}
System.out.println("\nOriginal string: " + a);
System.out.print("Reverse string: ");
//pop the words from the stack
while(!stack.empty()) {
System.out.print(stack.pop());
System.out.print(" ");
}
System.out.println("\n");
}
public static void main(String[] args) {
doStringReverseWord();
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Is intellij better than eclipse?
If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?
Write a program to find the whether a number is an Armstrong number or not?
What are the application of stack?
Can we make constructors static?
Why are functions called methods in java?
What is an object's lock and which object's have locks in java programming?
Can I learn java without any programming experience?
What is the intersection and union methods?
What are the difference between string, string builder, and string buffer in java?
Why do we need data serialization?
What is an interface in java? Explain
What are the types of strings?
Can an interface extend another interface?
Difference between static and dynamic class loading.