Click the Twitter icon to follow our tweets and
know more about us.

Sorting digits of a number in the same number

class sort_dig_asc
{
   public static void main(int n)
   {
       int c,s=0,d,d1;String nm=""+n;
       c=nm.length();
       for(int i=c;i>=0;i--)
       {
           for(int j=0;j<=i;j++)
           {
               s=n%(int)Math.pow(10,j);
               n=n/(int)Math.pow(10,j);
               d=n%10;
               n=n/10;
               d1=n%10;
               n=n/10;
               if(d1>d)
               {
                   d=d+d1;
                   d1=d-d1;
                   d=d-d1;
                }
                n=n*100+d1*10+d;
                n=n*(int)Math.pow(10,j)+s;
            }
        }
        System.out.println(n);
    }
}

Comments (0)

Post a Comment