JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Stack;
import java.util.StringTokenizer;
/**
Reversing a String by Word or by Character
Problem
:
You wish to reverse a string, a character,
or a word at a time.
Solution:
You can reverse a string by character easily,
using a StringBuilder. There are several
ways to reverse a string a word at a time.
One natural way is to use a StringTokenizer
and a stack. Stack is a class (defined in
java.util;) that implements an easy-to-use
last-in, first-out (LIFO) stack of objects.
*/
public class StringReverse{
public static void main(String[] args){
System.out.println(
" #Reversing a String by Word\n"
+" or by Character\n");
/*
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run