I tried entering an array and print only a certain index element Forgive me if my question is stupid, I am a beginner, The code runs but throws an exception when it reaches to the enter n part on line no 12 this is my code down below
import java.util.*;
public class array {
public static void main(String[] args) {
// ??classof 5 students
int []a=new int[5];
Scanner sc =new Scanner(System.in);
Scanner ob = new Scanner(System.in);
for(int i=0;i<5;i++)
{
a[i]=sc.nextInt();
}sc.close();
System.out.println("enter n");
int n = ob.nextInt();
System.out.println(","+a[n]+",");
}
}