將年份轉換成天幹地支
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]);
}
}
將年份轉換成天幹地支