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
What are loops in java? What are three types of loops?
What is Java Shutdown Hook?
What is ide with example?
What is fail first in java?
Is string an object?
What is the purpose of using javap?
What are the differences between Java 1.0 and Java 2.0?
what is daemon thread and which method is used to create the daemon thread? : Java thread
Why singleton class is used in java?
Can java arraylist hold different types?
Why is it called boolean?
What is bool mean?
Write a program in java to establish a connection between client and server?
What is the purpose of declaring a variable as final?
What is purpose of applet programming?