Write a program to find the order identification


Program
import java.util.Arrays; import java.util.Scanner; public class orderidentification { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the array size"); int a=sc.nextInt(); if(a<2 || a>10) { System.out.println(a+" is not a valid array size"); return; } int b[]=new int[a]; int count=0; System.out.println("Enter the elements"); for(int i=0;i<a;i++) { b[i]=sc.nextInt(); } int d[]= Arrays.copyOf(b,b.length); Arrays.sort(d); if(Arrays.equals(b,d)) { count++; } if(count>0) { for(int i=0;i<b.length;i++) { System.out.print(b[i]+" "); } System.out.print("are in ascending order"); return; } else { for(int i=0;i<a;i++) { System.out.print(b[i]+" "); } System.out.print("are not in ascending order"); return; } } }
Input
Output