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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad