
write a reverse program in java using string buffer.the input and out put as follows.
input- hi good mornig out put-ih doog ginrom.

Reverse String using StringBuffer class
The given code reverse each word of string and stored into the StringBuffer.
import java.util.*;
public class ReverseString{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
StringBuffer buffer=new StringBuffer();
System.out.println("Enter string: ");
String str=input.nextLine();
StringTokenizer stk=new StringTokenizer(str);
while(stk.hasMoreTokens()){
String st=stk.nextToken();
String reverse = new StringBuffer(st).reverse().toString();
buffer.append(reverse);
buffer.append(" ");
}
System.out.println("Reverse: " + buffer.toString());
}
}