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]);
        }

    }

  • 相关阅读:
    css
    AcWing 145 超市 (贪心)
    AcWing 144 最长异或值路径 (Trie)
    AcWing 143 最大异或对 (Trie)
    AcWing 142 前缀统计 (Trie)
    AcWing 141 周期 (KMP)
    AcWing 139 回文子串的最大长度 (哈希+二分 / Manacher)
    AcWing 136 邻值查找 (set)
    AcWing 133 蚯蚓 (队列)
    AcWing 131 直方图中最大的矩形 (单调栈)
  • 原文地址:https://www.cnblogs.com/suHDH/p/8836269.html
Copyright © 2011-2022 走看看