如何求出天干地支

​​​​​​​package zhu_yao;

public class FngFanQu {
    public void hanShuDiaoYong(){
        String[] tianGan={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
        String[] diZhi={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
        String[] array=new String[60];
        int index2=0;
        int index1=0;
        int index;
            for (index=0; index < tianGan.length; ) {
                    //index1++;
                    array[index2] = tianGan[index] + diZhi[index1];//运用引用类型拼接
                    index2++;
                    index1++;
                    if((index1==12)&&(index2<60)){//第一次判断index1何时归零
                        index1=0;
                    }
                    //index1++;//
                    if((index1==1)&&(index2==(12)||index2==(2*12)||index2==(3*12)||index2==(4*12))){//判断index1何时归零必须是最好时间
                        index1=0;
                    }
                index++;
                if((index==10)&&(index2<60)){
                    index=0;
                }
            }
        int i=0;//加强for部分
        for(String v:array){
            System.out.print(" "+v+"年");
            i++;
            if(i==15)//为了让每打印十五个就换行
            {
                System.out.println();
                i=0;
            }
        }

//                    int i=0;//一般for部分
//                    for(int index3=0;index3<60;index3++) {
//
//                            System.out.print(" " + array[index3]);
//                            i++;
//                            if(i==15)//为了让每打印十五个就换行
//                        {
//                            System.out.println();
//                            i=0;
//                        }
//                    }



    }
}

上一篇:python 寻找两个正序数组的中位数(leetcode)


下一篇:查找书籍 PTA C语言