switch statement
The switch statement can be programmed to select from a number of the execution path to perform, select these paths based on a single value.
first switch statement evaluates an expression, and the value and the value of several possible match case clause. Each has a value associated with the statement is executed, when the value of the expression is calculated, the control will be transferred to the expression value matches the first case clause executed.
. 1 Import java.util.Scanner;
2
. 3 public class A {
. 4
. 5 public static void main (String [] args)
. 6 {
. 7 int Grade, category;
. 8
. 9 Scanner Scan = new new Scanner (the System.in);
10
. 11 the System .out.print ( "enter number (0 to 100):" );
12 is Grade = scan.nextInt ();
13 is
14 category = Grade / 10 ;
15
16 of System.out.print ( "grades that are" );
. 17
18 is Switch (category)
. 19 {
20 is Case 10 :
21 is System.out.println ( "a perfect score." );
22 is BREAK ;
23 is Case . 9 :
24 System.out.println ( "well above average outstanding. . " );
25 BREAK ;
26 is Case . 8 :
27 System.out.println (" well above average. ". );
28 BREAK ;
29 Case . 7 :
30 System.out.println (" average .. ");
31 is BREAK ;
32 Case . 6 :
33 is System.out.println (. "Below average" );
34 is System.out.println ( "Instructor once"
35 + "describes in class" );
36 BREAK ;
37 [ default :
38 is System.out.println ( "not passed." );
39 }
40 }
41 }