Programming Examples

Java program to pass an integer as argument and check whether the digits are in ascending order or not


Write a program to pass an integer as argument and check whether the digits are in ascending order or not.

Solution

class AscendingDigits
{
	public static void main(int a)
	{
		int i,d,d1,f=0;
		for(i=a;i>9;i=i/10)
		{
			d=i%10;
			d1=(i/10)%10;
			if(d<d1)
				f=1;
		}
		if(f==0)
			System.out.println("Digits are in ascending order");
		else
			System.out.println("Digits are not in ascending order");
	}
}
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