Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - jdk writes a java program that accepts integers between 1 and 12 input by the user. If it does not meet the conditions, re-enter it and use the switch statement to output the corresponding month.
jdk writes a java program that accepts integers between 1 and 12 input by the user. If it does not meet the conditions, re-enter it and use the switch statement to output the corresponding month.

import java.util.*;

public class month {

public static void main(String[] args) {

int month;//Define the number entered by the user

Scanner scanner=new Scanner(System.in);

boolean flag=true;//Define the flag if the user chooses to exit, Then flag=false

while(flag){

System.out.print("Please enter an integer data between (1--12) (enter 0 to end) :");//Print prompt information

month=scanner.nextInt();//Accept keyboard input

switch(month){

case 0:System.out.println("You have exited");flag=false;break;

case 1:System.out.println("January 31 days");break;

case 2:System.out.println("February 28 or 29 days");break;

case 3:System.out.println("March 31 days"); break;

case 4:System.out.println("30 days in April");break;

case 5:System.out.println("31 days in May" );break;

case 6:System.out.println("30 days in June");break;

case 7:System.out.println("July 31 day");break;

case 8:System.out.println("August 31st");break;

case 9:System.out.println("九 30 days in October");break;

case 10:System.out.println("31 days in October");break;

case 11:System.out.println( "November 30 days");break;

case 12:System.out.println("December 31 days");break;

default:System.out .println("Input error, please re-enter");

}

}

}

}