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
Can we inherit inner class?
Can a class be declared as static?
Is boolean a wrapper class in java?
Why array is used in java?
What is the right data type to represent a price in java?
Which software is used for java programming?
What is locale in java?
Are arrays primitive data types?
What does java edition mean?
How do you sort arraylist in descending order?
Detail discussions on JVM, memory management and garbage collector.
What value is a variable of the string type automatically initialized?
give an example for encapsulation?
What do you understand by looping in java? Explain the different types of loops.
Difference between doublesummarystatistics, intsummarystatistics and longsummarystatistics ?