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 does the ‘static’ keyword mean? Is it possible to override private or static method in java?
How do you replace a string in java?
Is set ordered in java?
If an application has multiple classes in it, is it okay to have a main method in more than one class?
What is lastindexof in java?
What is a final class ?
What is function declaration?
What is the difference between Error, defect,fault, failure and mistake?
What is string array?
Does anyone still use java?
Why should we use singleton pattern instead of static class?
State the merge-sort principle and its time complexity.
What is an example of declaration?
What is the use of conditional statement?
What is pojo class in java?