第七章第三十三题(文化:中国生肖)(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
标签:Scanner,Chinese,System,Culture,year,Zodiac 来源: https://blog.csdn.net/jxh1025_/article/details/110384981