fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. final int[] array = new int[]{1, 2, 1, 2};
  4. for (int i= array.length - 1;i >=0;i--){
  5. if (array[i] == array[i-1]){
  6. System.out.print("you won");
  7. return;
  8. }
  9. }
  10. System.out.println("you did not win");
  11. }
  12. }
Runtime error #stdin #stdout #stderr 0.08s 46948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 4
	at Ideone.main(Main.java:5)