import java.util.*;
public class StringReverseWord {
private static void doStringReverseWord() {
String a = " Rohit Khariwal Mohit Parnami";
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();
}
}
*********************************************
i want to do somethig like this template
*********************************************
public class Reverser {
public static String reverse(char[] original) {
// Implement this method.
}
public static void main(String[] args) {
System.out.println("Original: " + args[0]);
System.out.println("Reversed: " + reverse(args[0].toCharArray()));
}
}