[ Write a program to input 10 number into an integer array and check weather they are in ascending order or not.
Program Code :
import java.util.*;
class Check_Ascending
public static void main(String args[])
{
int i,j,c=0,a=0,d=0;
int n[]=new int[10];
Scanner sc=new Scanner(System.in);
//Accepting 10 Array Element
for (i=0;i<10;i++)
{
System.out.print("Enter the Array Element = ");
n[i]=sc.nextInt();
}
//Checking Order of All the Array Element from Smallest to Largest or not
for (i=0;i<9;i++)
{
if(n[i]<n[i+1])
a++;
}
if(a==9)
System.out.println("Array in Ascending Order");
else
System.out.println("Array is not in Ascending Order");
}
}
No comments