Advertisement
gagan93

String Reverse without String API

Jan 7th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. class StringReverse
  2. {
  3.     public static void main(String[] args) throws java.io.IOException
  4.     {
  5.         int str[] = new int[100];
  6.         int i=0,j;
  7.         System.out.println("Enter a string");
  8.         while(true)
  9.         {
  10.             str[i]=System.in.read();
  11.             if(str[i++]==13)
  12.                 break;
  13.         }
  14.         String reversed="",simple = new String(str,0,i-1);
  15.         System.out.println(simple);
  16.  
  17.         // now reversing the string
  18.         for(j=i-1;j>=0;j--)
  19.             reversed+=((char)str[j]);
  20.         System.out.println(reversed);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement