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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz