2 testcases not passing

import java.util.*;
public class Main {
public static void main (String args[]) {

    Scanner sc= new Scanner(System.in);
    int len=sc.nextInt();
    int arr[]= new int[len];

    for(int i=0; i<len; i++){
        arr[i]=sc.nextInt();
    }

    //System.out.println(Arrays.toString(arr));

    int low=0;
    int high=0;

    while(low<len-1){
        int i=low;
        while(i!=len-1 && arr[i+1]==arr[i]+1){
            i++;
        }
        System.out.print(arr[low]+"->"+arr[i]+" ");
        low=i+1;
    }

}

}

@ANUKUL1509,

You need to print ranges like this l -> r, but if l == r then you just need to print l, just update your printing statements like this:

if(low != i){
System.out.print(arr[low]+"->"+arr[i]+" “);
}else{
System.out.print(arr[low]+” ");
}

Also, add below statement after while loop is executed,

if(low < len){
System.out.println(arr[low]);
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.