背景:我正在学习Java编程课程。
这是一个我想解决的简单问题:
“编写一个程序,提示用户输入分钟,并显示分钟的年数和天数。”
这是我到目前为止所写的:
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.");
}
}
这是我在Codenvy基于云的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)
任何指导都将不胜感激。