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

What data type is a string?

741


What is a type parameter in java?

778


what are the high-level thread states? : Java thread

789


Describe the various concepts related to object oriented programming (oop).

820


How do you identify if jvm is 32-bit or 64-bit from java program?

752


Is there any sort function in java?

860


What are the 6 mandatory procedures for iso 9001?

753


What is public static?

767


What is meant by bytecode?

780


Why is it called a string?

770


Which is easier .net or java?

866


What is boolean query?

768


what is bmg file and how to create that files?what will it contailn?

2158


What is a parent class in java?

804


How does system arraycopy work in java?

862