source file name:  ReverseDemo1.java

import java.io.*;

class ReverseDemo1

{

public static void main(String args[]) throws IOException

{

String str="";

try

{

DataInputStream dis=new DataInputStream(System.in);

System.out.println("enter any string ");

str=dis.readLine();

}

catch(Exception e)

{

System.out.println(e);

}

StringBuffer s=new StringBuffer(str);

System.out.println(""+s.reverse());//prints reverse string

String s1="How are you?";

String ss[]=s1.split(" ");

StringBuffer[] sb=new StringBuffer[ss.length];

for(int i=0;i<ss.length;i++)

{

sb[i]=new StringBuffer(ss[i]);

System.out.print(sb[i].reverse()+" ");

}

}

}


output:

D:\JavaPrograms\IOFilePrograms>javac ReverseDemo1.java
Note: ReverseDemo1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

D:\JavaPrograms\IOFilePrograms>java ReverseDemo1
enter any string
I scored 70 percent marks

skram tnecrep 07 derocs I
woH era ?uoy