zoukankan      html  css  js  c++  java
  • 将年份转换成天干地支

    import java.util.*;
    public class tiangan {

        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner reader=new Scanner(System.in);
            String tG[]={"葵","甲","乙","丙","丁","戊","己","庚","辛","壬"};
            String dZ[]={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
            String sX[]={"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
            int year,tg,dz,sx,cherk,a=0,b=0;
            System.out.println("公元前请选1,公元后请选0");
            cherk=reader.nextInt();
            System.out.println("请输入年份:");
            year=reader.nextInt();
            if(cherk==0)
            {
                //a=(year%10-3)>=0?a:-a;     不起作用!
    //            a=(year%10-3);
    //            if(a<0)
    //            {
    //                a=-a;
    //            }
                a=(year%10-3);
                if(a<0)
                {
                    a+=10;
                }
                b=(year)%12;
                b+=9;
                if(b>12)
                {
                    b-=12;
                }
                b-=1;
            }
            else if(cherk==1)
            {
                a=8-year%10;
                if(a<0)
                {
                    a+=10;
                }
                
                b=year%12;
                b=10-b;
                if(b<=0)
                {
                    b+=12;
                }
                b-=1;
            }
            else
            {
                System.out.println("输入有误");
            }
            System.out.println("天干地支:"+tG[a]+dZ[b]);
            System.out.println("生肖:"+sX[b]);
        }

    }

  • 相关阅读:
    TZOJ 1214: 数据结构练习题――线性表操作
    团体程序设计天梯赛 到底是不是太胖了
    TZOJ 数据结构实验:单链表元素插入
    Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
    Codeforces Round #511 (Div. 2)
    模板
    模板
    模板
    Codeforces Round #603 (Div. 2)
    模板
  • 原文地址:https://www.cnblogs.com/suHDH/p/8836269.html
Copyright © 2011-2022 走看看