Find the highest occurring digit in the prime numbers present between L and R (both inclusive)
In the code:

if (index != 0){
    System.out.println(index);
 }else{
    System.out.println(-1);
}


Using a ternary reduces clutter and improves readibility:

System.out.println(index == 0 ? -1 : index);