第七章第三十三题(文化:中国生肖)(Culture: Chinese Zodiac)

第七章第三十三题(文化:中国生肖)(Culture: Chinese Zodiac)

  • *7.33(文化:中国生肖)使用一个字符串数组存储动物名称来简化程序清单3-9的程序。
    *7.33(Culture: Chinese Zodiac)Use an array of strings to store animal names to simplify the program in listing 3-9.

  • 参考代码:

    package chapter07;
    
    import java.util.Scanner;
    
    public class Code_33 {
        public static void main(String[] args) {
            String[] zodiac = {"monkey","rooster","dog","pig","rat","ox","tiger","rabbit","dragon","snake","horse","sheep"};
            System.out.println("Enter a year:");
            Scanner input = new Scanner(System.in);
            int year = input.nextInt();
            System.out.println(zodiac[year % 12]);
        }
    }
    
    
  • 结果显示:

    Enter a year:
    2020
    rat
    
    Process finished with exit code 0
    
    
上一篇:李超线段树简易讲解


下一篇:特征重要性计算之LOFO与FLOFO