You are here:   HomeJava ProgrammingJava Array
by Dinesh Thakur Category: array

Algorithm For ReverseIT:

 

step 1: set s="Dat saw 1was Tad"

step 2: set len=s.length()

step 3: create two character array c[], cl[] of size len

step 4: initialize i=0

step 5: repeat through step-7 while (i < len)

step 6: c[i]=s. charAt(i)

step 7: i=i+ 1

step 8: initialize j=0

step 9: repeat through step-11 while (j < len)

step 10: c1[j]=c[len-1-j]

step 11: j=j+ 1

step 12: string sl =new String(c1)

step 13: print sl

step 14: Exit

 

Here is the Java Example for ReverseIT:

public class ReverseIT

{
       public static void main(String[] args)
       {
            String s="Dot saw I was Tod";
            int len=s.length();
            char[]c=new char[len];
            char[]c1=new char[len];
               for(int i=0;i<len;i++)
                   {
                      c[i]=s.charAt(i);
                   }
                      for(int j=0;j<len;j++)
                          {
                               c1[j]=c[len-1-j];
                          }
                               String sl=new String(c1);
                               System.out.println(sl);
        }
}

A string



What's New and Popular