Background: I'm taking a beginner Java coding class.
Here is a simple problem I'm looking to solve:
"Write a program that prompts the user to enter the minutes, and displays the number of years and days for the minutes."
This is what I have written so far:
import java.util.Scanner;
public class Main {
public static final int MINUTES_PER_YEAR = 525600;
public static final int MINUTES_PER_DAY = 1440;
public static void main(String[] args) {
// CH2.7 SOLUTION
// declare variables
int minutes;
int years;
int days;
// create scanner object to prompt user for minutes
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of minutes: ");
minutes = input.nextInt();
input.close();
years = minutes / MINUTES_PER_YEAR;
days = minutes % MINUTES_PER_DAY;
System.out.println(minutes + " minutes is approximately " + years + " years and " + days + " days.");
}
}
This is the error message I am receiving in the Codenvy cloud-based IDE:
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 Main.main(Main.java:21)
Any guidance would be appreciated.