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
Explain the overview of UDP messaging.
Explain about version control?
What is the symbol for space?
Why Java doesn’t support multiple inheritance?
When is the arraystoreexception thrown?
What is the list interface in java programming?
Explain hashset and its features?
What is method reference?
Why array is used in java?
Why object class is super class for every class in java?
Who is founder of java?
What does java edition mean?
What does compareto () do in java?
What is the SimpleTimeZone class?
Is logger a singleton?