Main.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Test switch() blocks
19 */
20public class Main {
21    public static void main(String args[]) {
22        int a = 1;
23
24        switch (a) {
25            case -1: System.out.print("neg one\n"); break;
26            case 0: System.out.print("zero\n"); break;
27            case 1: System.out.print("CORRECT (one)\n"); break;
28            case 2: System.out.print("two\n"); break;
29            case 3: System.out.print("three\n"); break;
30            case 4: System.out.print("four\n"); break;
31            default: System.out.print("???\n"); break;
32        }
33        switch (a) {
34            case 3: System.out.print("three\n"); break;
35            case 4: System.out.print("four\n"); break;
36            default: System.out.print("CORRECT (not found)\n"); break;
37        }
38
39        a = 0x12345678;
40
41        switch (a) {
42            case 0x12345678: System.out.print("CORRECT (large)\n"); break;
43            case 0x12345679: System.out.print("large+1\n"); break;
44            default: System.out.print("nuts\n"); break;
45        }
46        switch (a) {
47            case 57: System.out.print("fifty-seven!\n"); break;
48            case -6: System.out.print("neg six!\n"); break;
49            case 0x12345678: System.out.print("CORRECT (large)\n"); break;
50            case 22: System.out.print("twenty-two!\n"); break;
51            case 3: System.out.print("three!\n"); break;
52            default: System.out.print("huh?\n"); break;
53        }
54        switch (a) {
55            case -6: System.out.print("neg six!\n"); break;
56            case 3: System.out.print("three!\n"); break;
57            default: System.out.print("CORRECT (not found)\n"); break;
58        }
59
60        a = -5;
61        switch (a) {
62            case 12: System.out.print("twelve\n"); break;
63            case -5: System.out.print("CORRECT (not found)\n"); break;
64            case 0: System.out.print("zero\n"); break;
65            default: System.out.print("wah?\n"); break;
66        }
67
68        switch (a) {
69            default: System.out.print("CORRECT (default only)\n"); break;
70        }
71    }
72}
73