解题思路:
注意事项:导包
import java.util.Calendar;
import java.util.GregorianCalendar;
参考代码:
public class 第几天 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String date = in.next();
int year = Integer.valueOf(date.substring(0, 4));
int month;
int day;
if(date.charAt(6)=='/') {
month = Integer.valueOf(date.charAt(5))-1;
day = Integer.valueOf(date.substring(7));
}
else {
month = Integer.valueOf(date.substring(5,7))-1;
day = Integer.valueOf(date.substring(8));
}
Calendar cal = new GregorianCalendar(year, month, day);
System.out.println(cal.get(Calendar.DAY_OF_YEAR));
}
}
}
0.0分
0 人评分