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
Write a java program to generate fibonacci series ?
What is string :: npos?
What is the full form of jpeg?
Who developed java?
Can we call thread start () twice?
Explain yield() method in thread class ?
What is a ternary operator in java?
Is the milky way in a void?
How do you convert an int to a string in java?
Does java map allow duplicates?
What happens when heap memory is full?
Can we extend singleton class in java?
What is the use of runnable interface?
What is a superclass?
Where is stringbuffer stored?