this is the code for checking if the array is sorted or not. am not able to input values of N and array by scanner list.
can you please point out the mistakes?
Want to know the mistakes in the code
Replace 5 with N when calling sorted array
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int N= s.nextInt();
int[] a = new int[N];
for(int i=0; i<N; i++)
{
a[i]=s.nextInt();
}
//int[] a={9,3,3,4,5};
System.out.println(isSorted(N,a));
/*int N=Integer.parseInt(args[0]);
int[] a= new int[N];
for(int i=1; i<args.length-1; i++)
a[i-1]=Integer.parseInt(args[i]);
System.out.println(isSorted(N,a));
*/
}
public static boolean isSorted(int n, int[] ar)
{
//ArrayList<Integer> ar= new ArrayList();
//ar.add(" ");
n=n-1;
if(n<=0)
return true;
else{
if(ar[n]<ar[n-1]){
return false;
}
else
{
boolean A= isSorted(n-1, ar);
return A;
}
}
}
}