代码:
public class Test
{
public static void main(String[] args)
{
int year = 1996;//输入参数
int temp =(year-4)%12;
switch (temp)
{
case 0:
System.out.println("鼠");
break ;
case 1:
System.out.println("牛");
break ;
case 2:
System.out.println("虎");
break ;
case 3:
System.out.println("兔");
break ;
case 4:
System.out.println("龙");
break ;
case 5:
System.out.println("蛇");
break ;
case 6:
System.out.println("马");
break ;
case 7:
System.out.println("羊");
break ;
case 8:
System.out.println("猴");
break ;
case 9:
System.out.println("鸡");
break ;
case 10:
System.out.println("狗");
break ;
case 11:
System.out.println("猪");
break ;
}
}
}
最后
以上就是稳重天空最近收集整理的关于运用switch,用年份算出生肖的全部内容,更多相关运用switch内容请搜索靠谱客的其他文章。
发表评论 取消回复