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
How many bits are in a sentence?
What does += mean in java?
How do you call a reference in java?
Why webdriver is an interface?
What are memory tables?
What are the parts of methodology?
Explain when classnotfoundexception will be raised ?
What is __ init __ functions?
What is numel matlab?
Which collection allows duplicate values in java?
What do you mean by hashing?
Can you achieve runtime polymorphism by data members?
What is static variable with example?
Tell me a few examples of final classes defined in Java API?
What is the purpose of void?