Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /* IMPORTANT: class must not be public. */
  2. import java.util.*;
  3. /*
  4. * uncomment this if you want to read input.
  5. import java.io.BufferedReader;
  6. import java.io.InputStreamReader;
  7. */
  8.  
  9. class TestClass {
  10.  
  11.  
  12. public static boolean checkSorted(int arr[])
  13. {
  14. if(arr.length==1)
  15. {
  16. return true;
  17. }
  18. int newArr[]=new int[arr.length-1];
  19. for(int i=1;i<arr.length;i++)
  20. {
  21. newArr[i-1]=arr[i];
  22. }
  23.  
  24. boolean ans= checkSorted(newArr);
  25. if(!ans)
  26. {
  27. return false;
  28. }
  29.  
  30. if(arr[0]<=arr[1])
  31. {
  32. return true;
  33. }
  34. else
  35. {
  36. return false;
  37. }
  38. }
  39. public static void main(String args[] ) throws Exception {
  40. int size;
  41. Scanner sc=new Scanner(System.in);
  42. size=sc.nextInt();
  43. int arr[]=new int[size];
  44. for(int i=0;i<size;i++)
  45. {
  46. arr[i]=sc.nextInt();
  47. }
  48.  
  49. System.out.println(checkSorted(arr));
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement