zoukankan      html  css  js  c++  java
  • 小程序1-生肖猜年龄

    输入生肖猜测你的年龄,输入年龄得出你的生肖。ps:这里的年龄实岁而不是虚岁。

    效果图:

    源代码:

    package age;

    import java.text.SimpleDateFormat;
    import java.time.Year;
    import java.util.Date;
    import java.util.Scanner;

    import javax.xml.soap.SAAJResult;

    public class age {

    static String []age = {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"}; //数组存放生肖

    public static void main(String[] args) {
    //获取今年的年份
    Date date =new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
    int year = Integer.parseInt(sdf.format(date));


    int index;
    System.out.println("菜单:1.年龄转生肖 2.生肖猜年龄");
    System.out.println("输入你的选择:");
    Scanner scanner = new Scanner(System.in);
    index = scanner.nextInt();
    switch (index) {
    case 1:
    System.out.println("年龄转生肖");
    SearchA();
    break;
    case 2:
    System.out.println("生肖转年龄");
    SearchB(year);
    break;
    default:
    break;
    }
    }

    public static void SearchA() //年龄转生肖
    {

    System.out.println("输入你的年龄");
    Scanner scanner = new Scanner(System.in);
    int Myage = scanner.nextInt();
    int i = (Myage%12);
    System.out.println("你的生肖是: "+age[i]);

    }

    public static void SearchB(int year) //生肖转年龄
    {
    //1900年是鼠年
    int i = (year-1900)%12;
    System.out.println("今年是: "+age[i]+"年");
    System.out.println("输入你的生肖");
    Scanner scanner = new Scanner(System.in);
    String this_SX = scanner.nextLine();
    //System.out.println(this_SX);
    int m=0;
    int outAge=0;
    for(int j=0;j<12;j++)
    {
    if(age[j].equals(this_SX))
    m=j;
    }
    if(m>i)
    {
    outAge = (i+12-m);
    while(outAge<150)
    {

    System.out.println("你的年龄可能是:"+outAge+"岁");
    outAge+=12;
    }

    }
    else //比今年大
    {
    outAge = i-m;
    while(outAge<150)
    {
    System.out.println("你的年龄可能是:"+outAge+"岁");
    outAge+=12;
    }
    }



    }

    }

  • 相关阅读:
    【翻译】JavaScript循环和作用域
    【js-xlsx和file-saver插件】前端导出数据到excel
    H5混合开发进阶
    一分钟搞定vue全局注册事件eventBus
    cordova+vue构建app进阶
    LayaBox进阶之UI管理器
    Layabox进阶之资源加载
    H5混合开发进阶之inspect调试
    认识json
    正则学习记录
  • 原文地址:https://www.cnblogs.com/fyz666/p/8451878.html
Copyright © 2011-2022 走看看