**3.4(随机月份)编写一个随机产生1和12之间整数的程序,并且根据数字1,2,……,12显示相应的英文月份:January,February,……,December。 **3.4(Random month) Write a program that randomly generates an integer between 1 and 12 and displays the English month names January, February, . . . , December for the numbers 1, 2, . . . , 12, accordingly.
参考代码:
package chapter03;import java.util.Random;publicclassCode_04{publicstaticvoidmain(String[] args){
Random r =newRandom();int month = r.nextInt(12)+1;switch(month){case1:System.out.println("January");break;case2:System.out.println("Febrary");break;case3:System.out.println("March");break;case4:System.out.println("April");break;case5:System.out.println("May");break;case6:System.out.println("June");break;case7:System.out.println("July");break;case8:System.out.println("August");break;case9:System.out.println("September");break;case10:System.out.println("October");break;case11:System.out.println("November");break;case12:System.out.println("December");break;}}}
第三章第四题(随机月份)(Random month)**3.4(随机月份)编写一个随机产生1和12之间整数的程序,并且根据数字1,2,……,12显示相应的英文月份:January,February,……,December。**3.4(Random month) Write a program that randomly generates an integer between 1 and 12 and displays the English month names January, February