import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.Scanner;//输入某年某月某日,判断这一天是这一年的第几天?public class Test { public static void main(String[] args) throws ParseException { Scanner sc = new Scanner(System.in); System.out.println("请输入你的日期,格式为yyy-MM-dd:"); SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd"); Date d; String s ; while (true) { s = sc.nextLine(); try { d = sdf.parse(s); break; } catch (Exception e) { System.out.println("请输入正确日期yyy-MM-dd格式:"); } } Calendar c = Calendar.getInstance(); c.setTime(d); System.out.println(s+"是这一年的第"+c.get(Calendar.DAY_OF_YEAR)+"天"); }}