题解 | #今年的第几天#
今年的第几天
http://www.nowcoder.com/practice/cc6ad889f95c49c08da1b338dd2e07ab
利用calendar工具类计算今年的第几天
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
int month = sc.nextInt();
int day = sc.nextInt();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
String monthstr = month > 9 ? month+"" : "0"+ month;
String str = year + "-"+ monthstr +"-" + day;
try{
cal.setTime(df.parse(str));
} catch (Exception e){
e.printStackTrace();
}
System.out.print(cal.get(6));
}
}