将年份转换成天干地支
Posted suhdh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将年份转换成天干地支相关的知识,希望对你有一定的参考价值。
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]);
}
}
以上是关于将年份转换成天干地支的主要内容,如果未能解决你的问题,请参考以下文章
2020年第十一届蓝桥杯 - 国赛 - Java大学C组 - F.天干地支