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
How can we make string upper case or lower case?
What is the difference between an object-oriented programming language and object-based programming language?
When a byte datatype is used?
Write a java program to generate fibonacci series ?
Can I import same package/class twice?
What is meant by overloading?
What is keyword in oop?
Can this keyword be used to refer static members?
What is a Hash Table? What are the advantages of using a hash table?
What is difference between module and function?
What is the basic concepts of OOPS?
What is a numeric literal?
Describe what happens when an object is created in java ?
What if I write static public void instead of public static void in java?
How many classes can any class inherit java?