计算复活节星期天的日期

计算复活节星期天的日期,第1张

计算复活节星期天的日期

试试这个:

import java.util.Scanner;class Easter{    public static void main(String[] args)    {        System.out.print("Please enter a year to calculate Easter Sundayn>");        Scanner s = new Scanner(System.in);        int inputted = getResult(s);        while(inputted <= 0)        { System.out.print("Expected a positive year. Please try again:n>"); inputted = getResult(s);        }        System.out.println(getEasterSundayDate(inputted));    }    private static int getResult(Scanner s)    {        while(!s.hasNextInt())        { System.out.print("Expected a valid year. Please try again:n>"); s.nextLine();        }        return s.nextInt();    }    public static String getEasterSundayDate(int year)    {        int a = year % 19, b = year / 100, c = year % 100, d = b / 4, e = b % 4, g = (8 * b + 13) / 25, h = (19 * a + b - d - g + 15) % 30, j = c / 4, k = c % 4, m = (a + 11 * h) / 319, r = (2 * e + 2 * j - k - h + m + 32) % 7, n = (h - m + r + 90) / 25, p = (h - m + r + n + 19) % 32;        String result;        switch(n)        { case 1:     result = "January ";     break; case 2:     result = "February ";     break; case 3:     result = "March ";     break; case 4:     result = "April ";     break; case 5:     result = "May ";     break; case 6:     result = "June ";     break; case 7:     result = "July ";     break; case 8:     result = "August ";     break; case 9:     result = "September ";     break; case 10:     result = "October ";     break; case 11:     result = "November ";     break; case 12:     result = "December ";     break; default:     result = "error";        }        return result + p;    }}

2001
结果的输入
April 15
作为输出



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5104342.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存