E mới học java, cho e hỏi đây là lỗi gì vậy? E cảm ơn
public class test4 {
public static void main(String[] args) {
Scanner atom = new Scanner(System.in);
System.out.printf("Nhập số sinh viên: ");
int x = atom.nextInt();
int[] mảng = new int[x];
System.out.println("Nhập phần tử của mảng: ");
for (int i = 1; i <= x; i++) {
System.out.printf("a[%d] = ", i);
mảng[i] = atom.nextInt();
}
System.out.println("Các phần tử của mảng");
}
}
Nhập số sinh viên: 2
Nhập phần tử của mảng:
a[1] = 3
a[2] = 1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at test4.main(test4.java:13)
Process finished with exit code 1