I'm getting nzec run time error can someone tell me what i did wrong

import java.util.Scanner;
import java.util.;
import java.lang.
;
import java.io.*;

class CodeChef {

public static void main(String[] args) {

    Scanner s1 = new Scanner(System.in);
    int a = s1.nextInt();
    boolean duplicates = false;
    int array[] = new int[a];

    for(int i = 0; i <= a; i++) {
        array[i] = s1.nextInt();
    }

    for (int j = 0; j < array.length; j++) {
        for(int k = j+1; k < array.length; k++) {
            if(k != j && array[j] == array[k]) {
                duplicates = true;
            }
            if(duplicates = true) {
                System.out.print("YES");
            }
            else {
                System.out.print("NO");
            }
        }
    }
}

}

First, format your code

Then, think about this from… anyone else’s perspective. How would we figure this out without knowing the problem, your intended logic, etc.?

1 Like