Recursion Array

PHOTO EMBED

Sat Jan 08 2022 18:00:23 GMT+0000 (Coordinated Universal Time)

Saved by @shan2398 #recursion #arrays

import java.util.*;

public class Main {

  public static void main(String[] args) {
    // Write your code here

    int[] arr = {1,2,7,4,5};

    boolean ans = sorted(arr, 0);

    System.out.print(ans);

  }

  public static boolean sorted(int[] arr,int index) {
    if(index == arr.length-1){
      return true;
    }

    return arr[index]<arr[index+1] && sorted(arr, index+1);

  }
}
content_copyCOPY

To check if an array is sorted using recursion