Why does the user input not accept the value?

This is my first program in java, and I have to write a program that codes for a calendar and I am getting this error message for the line “int day=scan2.nextInt();” (line 26) runs in the console


Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Calendar.main(Calendar.java:26)


here is my code:

public static void main(String[] args) {
    System.out.println("MONTHLY CALENDAR");
	System.out.println("This program displays a calendar.  You need to provide the year, and");
	System.out.println("the day of the week on which January 1 falls");

    System.out.println("       ");
		
		
    Scanner scanY = new Scanner(System.in); 
	System.out.print("Enter the year for which you would like a calendar:"); // user inputs year
	int year = scanY.nextInt(); 
	scanY.close(); 
		
	System.out.println("       ");
		
	System.out.println("Enter the code number for January 1: ");
	System.out.println("0- Sun  1- Mon  2- Tue  3- Wed  4- Thu  5- Fri  6- Sat");
		
		
	Scanner scan2 = new Scanner(System.in);
	System.out.print("Enter the day code now:");
	int day=scan2.nextInt();
	scan2.close();

}