Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.text.SimpleDateFormat;
  2. import java.util.Calendar;
  3. import java.util.GregorianCalendar;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class ch2_1
  8. {
  9.  
  10. /**
  11. * @param args
  12. */
  13. public static void main(String[] args)
  14. {
  15. // TODO Auto-generated method stub
  16. Scanner input=new Scanner(System.in);
  17. System.out.print("请输入起始年份:");
  18. int year=input.nextInt();
  19. System.out.print("请输入打算输出未来几年:");
  20. int n=input.nextInt();
  21. getBlackFri(year,n);
  22.  
  23. }
  24.  
  25. //打印未来几年的黑色星期五,判断每个月的13号是否是星期五
  26. public static void getBlackFri(int year,int n)
  27. {
  28. //year为输入的年份,n为未来多少年
  29. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd E");
  30. // int years = Integer.parseInt(year);
  31. int k=0;
  32. // Calendar cal = new GregorianCalendar();
  33. Calendar cal = Calendar.getInstance();
  34. while(k<n)
  35. {
  36. for (int i = 0; i < 12; i++)
  37. {
  38. cal.set(year, i,13);
  39. if(5==(cal.get(Calendar.DAY_OF_WEEK)-1))
  40. {
  41. System.out.println("黑色星期五:"+sdf.format(cal.getTime()));
  42. }
  43. }
  44. year++;
  45. k++;
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement