代码:

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,用年份算出生肖

相关文章:

  • 2021-12-10
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-12
  • 2021-12-14
  • 2022-12-23
  • 2023-03-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2021-12-04
  • 2021-12-07
  • 2022-12-23
相关资源
相似解决方案