Programming Examples
Java program to input an integer as argument and print the number by having the digits arranged in ascending order
Write a program to input an integer as argument, and print the number by having the digits arranged in ascending order.
Solution
class Ascending
{
public static void main(int n)
{
int i,s=0,c=0,d,j;
for(i=9;i>=0;i--)
{
for(j=n;j>0;j=j/10)
{
d=j%10;
if(d==i)
s+=d*(int)Math.pow(10,c++);
}
}
System.out.println(“New number=”+s);
}
}
Output