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 differences between collection api and stream api?
How infinite loop is declared?
Is sizeof a keyword in java programming?
What are the steps involved to create a bean?
What are features of java?
What is the difference between the final method and abstract method?
What do you mean by jjs in java8?
Can we have two main methods in a java class?
Which collection is ordered in java?
Why do we use variables?
What is the maximum size of list in java?
What is instance example?
How will you compute size of a structure?
Can a serialized object be transferred via network?
Can we have multiple public classes in a java source file?