Java语言程序设计(基础篇)第十版 编程练习题3.4(随机月份)

编写一个随机产生1和12之间整数的程序,并且根据数字1,2….12,显示相应的英文月份: January,February,…,December.


public class RandomMonth {

    public static void main(String[] args) {

        int month = (int)(Math.random() * 12);

        switch(month)
        {
        case 1: System.out.println("January");break;
        case 2: System.out.println("February");break;
        case 3: System.out.println("March");break;
        case 4: System.out.println("April");break;
        case 5: System.out.println("May");break;
        case 6: System.out.println("June");break;
        case 7: System.out.println("July");break;
        case 8: System.out.println("August");break;
        case 9: System.out.println("September");break;
        case 10: System.out.println("October");break;
        case 11: System.out.println("November");break;
        case 12: System.out.println("Decemer");break;

        }

    }

}

你可能感兴趣的:(java)