daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Aug 13th, 2017 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //進階作業1.1
  2. //       //第一種方法
  3. //       String num = "123";
  4. //       StringBuffer reverse = new StringBuffer(num).reverse();
  5. //       System.out.println(reverse);
  6. //       //第二種方法
  7. //       int num2 = Integer.parseInt(num);
  8. //       String a = Integer.toString(num2 / 100);
  9. //       int b = num2 % 100;
  10. //       String c = Integer.toString(b / 10);
  11. //       String e = Integer.toString(b % 10);
  12. //       System.out.println(e+c+a);
  13. //      //進階作業1.2
  14. //       //做租書店系統
  15. //       
  16. //       
  17.         //進階作業2
  18.         Calendar cal = Calendar.getInstance();
  19.         int nowYear = cal.get(Calendar.YEAR);
  20.         LocalDate date = LocalDate.now();
  21.         int OnedayOfTheYear = date.getDayOfYear();
  22.         System.out.println("從今年一月一號到現在總共有" + OnedayOfTheYear + "天");
  23.        
  24.         int[] notLeapYear={31,28,31,30,31,30,31,31,30,31,30,31};
  25.         int inputYear;
  26.         int inputMonth;
  27.         int inputDay;
  28.         int totalDaysOfYears = 0;
  29.         int totalDaysOfMonth = 0;
  30.        
  31.         Scanner scannerYear = new Scanner(System.in);
  32.         inputYear = scannerYear.nextInt();
  33.         if(inputYear >0){
  34.             if(inputYear < nowYear)
  35.                 totalDaysOfYears = ((nowYear-1) - inputYear)*365;
  36.             else if(inputYear == nowYear)
  37.                 totalDaysOfYears = 0;
  38.             else
  39.                 System.out.printf("沒有人的生日是在今年以後");
  40.         }else{
  41.             System.out.printf("不算西元前%d年,請重新輸入",inputYear);
  42.         }
  43.        
  44.         Scanner scannerMonth = new Scanner(System.in);
  45.         inputMonth = scannerYear.nextInt();
  46.         if(inputMonth >0 && inputMonth <= 12){
  47.         }else{
  48.             System.out.println("月份只有到12月喔,請重新輸入");
  49.         }
  50.        
  51.         Scanner scannerDay = new Scanner(System.in);
  52.         inputDay = scannerDay.nextInt();
  53.         if(inputDay >0 && inputDay <= 31){
  54.         }else{
  55.             System.out.println("一個月最多有31天喔,請重新輸入");    
  56.         }
  57.        
  58.         for(int month=0;month<=inputMonth-2;month++){
  59.             totalDaysOfMonth += notLeapYear[month];
  60.         }
  61.         if(inputYear != nowYear)
  62.             totalDaysOfMonth += inputDay;  
  63.        
  64.         int dayOfBirthday =  OnedayOfTheYear + totalDaysOfYears - totalDaysOfMonth ;
  65.         System.out.println("你已經活了" + dayOfBirthday + "天");
RAW Paste Data
Top