Programming Examples

Java program to input 10 integers and check whether the entered numbers are in ascending order or not


Write a program to input 10 integers and check whether the entered numbers are in ascending order or not.

For Example,

INPUT: Enter 10 numbers: 10 12 13 25 45 55 67 78 106 122

OUTPUT: The numbers are in ascending order.

INPUT: Enter 10 numbers: 25 34 56 67 12 32 43 21 23 111

OUTPUT: The numbers are not in ascending order.

Solution

class AscendingNumber
{
	public static void main(Strign arr[])
	{
		Scanner sc=new Scanner(System.in);
		int i,n,f=0,p=0;
		System.out.println("Enter 10 integers:");
		for(i=1;i<=10;i++)
		{
			n=sc.nextInt();
			if(i>1)
			{
				if(n<p)
				f=1;
			}
			p=n;
		}
		if(f==0)
			System.out.println("The numbers are in ascending order");
		else
			System.out.println("The numbers are not in ascending order");
	}
}
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