summaryrefslogtreecommitdiffstats
path: root/test/015-switch/src/Main.java
blob: dd97a8c60b8662893f157031d0d921852ad4720e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Test switch() blocks
 */
public class Main {
    public static void main(String args[]) {
        int a = 1;

        switch (a) {
            case -1: System.out.print("neg one\n"); break;
            case 0: System.out.print("zero\n"); break;
            case 1: System.out.print("CORRECT (one)\n"); break;
            case 2: System.out.print("two\n"); break;
            case 3: System.out.print("three\n"); break;
            case 4: System.out.print("four\n"); break;
            default: System.out.print("???\n"); break;
        }
        switch (a) {
            case 3: System.out.print("three\n"); break;
            case 4: System.out.print("four\n"); break;
            default: System.out.print("CORRECT (not found)\n"); break;
        }

        a = 0x12345678;

        switch (a) {
            case 0x12345678: System.out.print("CORRECT (large)\n"); break;
            case 0x12345679: System.out.print("large+1\n"); break;
            default: System.out.print("nuts\n"); break;
        }
        switch (a) {
            case 0x12345678: System.out.print("CORRECT (large2)\n"); break;
            case 0x12345700: System.out.print("large+many\n"); break;
            default: System.out.print("nuts\n"); break;
        }
        switch (a) {
            case 57: System.out.print("fifty-seven!\n"); break;
            case -6: System.out.print("neg six!\n"); break;
            case 0x12345678: System.out.print("CORRECT (large3)\n"); break;
            case 22: System.out.print("twenty-two!\n"); break;
            case 3: System.out.print("three!\n"); break;
            default: System.out.print("huh?\n"); break;
        }
        switch (a) {
            case -6: System.out.print("neg six!\n"); break;
            case 3: System.out.print("three!\n"); break;
            default: System.out.print("CORRECT (not found)\n"); break;
        }

        a = -5;
        switch (a) {
            case 12: System.out.print("twelve\n"); break;
            case -5: System.out.print("CORRECT (not found)\n"); break;
            case 0: System.out.print("zero\n"); break;
            default: System.out.print("wah?\n"); break;
        }

        switch (a) {
            default: System.out.print("CORRECT (default only)\n"); break;
        }

        a = -10;
        switch (a) {
            case -10: System.out.print("CORRECT big sparse / first\n"); break;
            case -5: System.out.print("neg five\n"); break;
            case 0: System.out.print("zero\n"); break;
            case 5: System.out.print("five\n"); break;
            case 10: System.out.print("ten\n"); break;
            case 15: System.out.print("fifteen\n"); break;
            case 20: System.out.print("twenty\n"); break;
            case 50: System.out.print("fifty\n"); break;
            case 100: System.out.print("hundred\n"); break;
            default: System.out.print("blah!\n"); break;
        }

        a = 100;
        switch (a) {
            case -10: System.out.print("neg ten\n"); break;
            case -5: System.out.print("neg five\n"); break;
            case 0: System.out.print("zero\n"); break;
            case 5: System.out.print("five\n"); break;
            case 10: System.out.print("ten\n"); break;
            case 15: System.out.print("fifteen\n"); break;
            case 20: System.out.print("twenty\n"); break;
            case 50: System.out.print("fifty\n"); break;
            case 100: System.out.print("CORRECT big sparse / last\n"); break;
            default: System.out.print("blah!\n"); break;
        }

        for (a = 253; a <= 258; a++) {
          switch (a) {
            case 254: System.out.println("254"); break;
            case 255: System.out.println("255"); break;
            case 256: System.out.println("256"); break;
            case 257: System.out.println("257"); break;
            default: System.out.println("default"); break;
          }
        }
    }
}