The switch judgment statement in Java typically USES an instance
- 2020-04-01 03:53:59
- OfStack
The following is an example of a typical switch syntax.
import java.util.Scanner;
public class JudgeMonth {
public static void main(String[] arg){
Scanner scan = new Scanner(System.in);
System.out.println(" Please enter month :");
int month = scan.nextInt();
switch(month){
case 12:
case 1:
case 2:
System.out.println(" In the winter ");
break;
case 3:
case 4:
case 5:
System.out.println(" In the spring ");
break;
case 6:
case 7:
case 8:
System.out.println(" In the summer ");
break;
case 9:
case 10:
case 11:
System.out.println(" In the fall ");
break;
default:
System.out.println(" No month! Please re-enter .");
}
}
}