怎么改程序,系统获取当前时间后,自动输出属相和干支,就不用自己输入年份了。

package huu;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Scanner;


public class Test {

 

    /**

     * 计算对应年份的生肖

     * @param year 给定年份

     * @return 返回生肖的字符串

     */

    private static String getZodica(int year) {

        final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇",

                "马", "羊", "猴", "鸡", "狗", "猪" };

        return Animals[(year - 4) % 12];

    }

 

    /**

     * 计算对应年份的干支

     * @param year 给定年份

     * @return 返回干支字符串

     */

    private static String Gan_Zhi(int year) {

        final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",

                "辛", "壬", "癸" };

        final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",

                "未", "申", "酉", "戌", "亥" };

        return (Gan[(year-4) % 10] + Zhi[(year-4) % 12]);

    }

   public static void Time(){

  System.out.println("请输入年份:");

   }

   


    public static void main(String[] args) {

    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Calendar now = java.util.Calendar.getInstance();

    System.out.println(dateformat.format(now.getTime()));//获取当前系统时间

    

    java.util.Calendar   startData=java.util.Calendar.getInstance();

    java.util.Calendar   endData=java.util.Calendar.getInstance();

    startData.set(2015,9,25);

    endData.set(2017,8,13);//分别输出两个时间的值

    Long  dateLen = Math.abs((endData.getTimeInMillis()-startData.getTimeInMillis())/(24*60*60*1000));//获取相减值的绝对值

    System.out.println(dateLen);//输出时间差

    

    

  

    Scanner scanner  = new Scanner(System.in);

    System.out.print("请输入年份:");

    int year = scanner.nextInt();

    System.out.println("生肖:"+getZodica(year)+"\n干支:"+Gan_Zhi(year));

    }

}



Yoloiii
浏览 1471回答 3
3回答

慕的地8582982

KNXHMJCMPSODTZQFZWWVQHHUQUAKOOHSNEVCVQHIWFJANGDNKBRZSWDEUFFMNEMVWUTWSJWHVWJTQZQCAHOOVOIZMCDRRYNCFVZRYKMWNWXNXBNBOOFMSNAPDUHWPAZJPMKVFVFDKENOXRYLLRIIFWTSWXIGQHKEKRESVBIUBBYSIOLYLXLSFITQLLMROIFFCMDMKTFGKWJJGANXKSJZUCGNKNBQSFIQNDNATQWOLNBHUDFYVZBNRVFVZSCCJRXUHMSCVFUYSFPJADRUEBLGRAHVFMVEVXVUKEUORORYMAXKFVFMWRVSSVMTLLOOYVEGGWVDMFPSPMZWANKBRADXORHHEVQRUEXFEKKLCAQGFJLYLBLBVFPOMJGDMAHNROBFMJJLILJPCLYUMMWJDZDGXVZMMLMWQKOXBVGDWHIMJDMWDFUXYYVFLVVDMIIQZNARXEJCPIIZFFHBODQUXBRINDGHUZMBEBCIKTESKLOPQGLERVUZTGLZWDDNGVSSSFGZRENUYKUESIJCCYCFFVHJMMGJMTCWQMWSLMFEJZNESCBVVZICPQGZNFIBKTDDRRNEEENQMTBPFYJJGTWQZMMSBOGFFNOYLCLVSCMPCZZQNNMXOXQTQHUNVMJSDAAJAWRXWDGGEZMMTXJHEXLLLURHMOZWSXGDNKUBRKRJTWNNXTKJZAUVLOHOYPYBVBEIPFMMRGWMEXFZSJJLIPDPZPZONHOXKELBEOZTWGWZQGQQGWYBIIERKQKKSFYEETEHFZCZJAIENERGNDCGMPVFPHRSDBQOBHSZDNYMFGEZFHAOBUAKAXQCCZMXDBXULCPSCCSYGZFPIQBKUNWNQBCSOKKLXGKDOURHUEFOFSSRFDDHQVERXKXN

To_The_Moon

一般来说你得给出一个作为定点的常量。比如1948.是鼠年,你以这个常量为标准去计算其他年份就行了。比1948多出来多少年的除以12这个轮回剩下的增量。加到年份里去,就能算出来是什么年了。比1948小的年份则往前反推。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java