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 */ 20 public 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 0x12345678: System.out.print("CORRECT (large2)\n"); break; 48 case 0x12345700: System.out.print("large+many\n"); break; 49 default: System.out.print("nuts\n"); break; 50 } 51 switch (a) { 52 case 57: System.out.print("fifty-seven!\n"); break; 53 case -6: System.out.print("neg six!\n"); break; 54 case 0x12345678: System.out.print("CORRECT (large3)\n"); break; 55 case 22: System.out.print("twenty-two!\n"); break; 56 case 3: System.out.print("three!\n"); break; 57 default: System.out.print("huh?\n"); break; 58 } 59 switch (a) { 60 case -6: System.out.print("neg six!\n"); break; 61 case 3: System.out.print("three!\n"); break; 62 default: System.out.print("CORRECT (not found)\n"); break; 63 } 64 65 a = -5; 66 switch (a) { 67 case 12: System.out.print("twelve\n"); break; 68 case -5: System.out.print("CORRECT (not found)\n"); break; 69 case 0: System.out.print("zero\n"); break; 70 default: System.out.print("wah?\n"); break; 71 } 72 73 switch (a) { 74 default: System.out.print("CORRECT (default only)\n"); break; 75 } 76 77 a = -10; 78 switch (a) { 79 case -10: System.out.print("CORRECT big sparse / first\n"); break; 80 case -5: System.out.print("neg five\n"); break; 81 case 0: System.out.print("zero\n"); break; 82 case 5: System.out.print("five\n"); break; 83 case 10: System.out.print("ten\n"); break; 84 case 15: System.out.print("fifteen\n"); break; 85 case 20: System.out.print("twenty\n"); break; 86 case 50: System.out.print("fifty\n"); break; 87 case 100: System.out.print("hundred\n"); break; 88 default: System.out.print("blah!\n"); break; 89 } 90 91 a = 100; 92 switch (a) { 93 case -10: System.out.print("neg ten\n"); break; 94 case -5: System.out.print("neg five\n"); break; 95 case 0: System.out.print("zero\n"); break; 96 case 5: System.out.print("five\n"); break; 97 case 10: System.out.print("ten\n"); break; 98 case 15: System.out.print("fifteen\n"); break; 99 case 20: System.out.print("twenty\n"); break; 100 case 50: System.out.print("fifty\n"); break; 101 case 100: System.out.print("CORRECT big sparse / last\n"); break; 102 default: System.out.print("blah!\n"); break; 103 } 104 } 105 } 106