String Reverse in Java...!

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


Please Help Members By Posting Answers For Below Questions

How can we make string upper case or lower case?

595


What is the difference between an object-oriented programming language and object-based programming language?

563


When a byte datatype is used?

561


Write a java program to generate fibonacci series ?

567


Can I import same package/class twice?

490






What is meant by overloading?

584


What is keyword in oop?

516


Can this keyword be used to refer static members?

542


What is a Hash Table? What are the advantages of using a hash table?

603


What is difference between module and function?

535


What is the basic concepts of OOPS?

684


What is a numeric literal?

521


Describe what happens when an object is created in java ?

543


What if I write static public void instead of public static void in java?

577


How many classes can any class inherit java?

504