switch语句实现输入1~12之间的整数所对应的月份

留个笔记:


import java.util.*;


/**
 *@描述:TODO switch 语句实现输入 1~12 之间的整数所对应的月份
 *
 *@类名称: Month
 *@作者: 宋延军
 *@邮箱: [email protected]
 *@日期: Feb 20,2012 5:08:37 PM
 */
public class Month {

	public Month() {
	}

	public static void main(String[] args) {
		
		System.out.print("请输入一个1到12之间的整数:");
		Scanner reader = new Scanner(System.in);
                int month;
		test: while (1 == 1) {

			month = reader.nextInt();
			if ((month < 1) || (month > 12)) {

				System.out.print("sorry,你输入的数不符合条件,请重新输入:");

				// month=reader.nextInt();
				continue test;
			} 
                        else{
				break;
                         }		
                }
		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("December");
			break;

		}

	}
}



Over!!!


你可能感兴趣的:(JAVA)