日期:2014-05-20 浏览次数:20741 次
Calendar calendar = Calendar.getInstance(); calendar.set(year,month,date); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
------解决方案--------------------
public static void main(String[] args) { Scanner input = new Scanner(System.in); //获取键盘输入的年月日 int year = input.nextInt(); int month = input.nextInt(); int date = input.nextInt(); Calendar calendar = Calendar.getInstance(); //设置calendar表示的日期,这里注意在Calendar中月是从0开始,也就是1月的时候month应设为0; calendar.set(year, month-1, date); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); System.out.println(dayOfYear); }