public class Q1 {
 
 void determine (int[] val) {
  
  int i = 0;
  
 
  
  while (i <= 4) {
   
   if (val[i-1] != val[i+3]) {
    System.out.println(val[i] + "and" + val[i+3] + "is different"); //for comparative first value and second value
   }
   
   else if (val[i-1] != val[i]) {
    
    System.out.println(val[i] + "and" + val[i+1] + "is different");
   }

   else {
    
    System.out.println(val[i] + "and" + val[i+1] + "is same");
    
   }
   i++;
  }
 }
 

 public static void main(String[] args) {
  
  Q1 q = new Q1();
  int[] val = {1, 2, 5, 5, 3};
  q.determine(val);
 }

}

이렇게 선언했는데

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
 at Q1.determine(Q1.java:12)
 at Q1.main(Q1.java:35)

이런 에러 뜨면서 안되네요 ㅠㅠ

제발 도와주세요 ㅠㅠ