KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > OddSwitches


1 /**
2  * OddSwitches
3  *
4  * @author < a HREF="mailto:jddixon@users.sourceforge.net">Jim Dixon</a>
5  */

6
7 public class OddSwitches implements org.quilt.cl.RunTest {
8     
9     public OddSwitches() { }
10
11     // called for values >= 1000
12
private int fallsThrough ( int i ) {
13        switch (i) {
14             case 1001:
15             case 1003:
16                 return 91;
17             case 1005:
18             default:
19                 return 101;
20        }
21     }
22
23     // positive values < 1000
24
private int noDefault (int i) {
25         switch (i) {
26             case 3: return 31;
27             case 5: return 53;
28             case 7: return 71;
29         }
30         int x = 9;
31         return x;
32     }
33
34     // values < 0
35
private int oddDefault(int i) {
36         switch (i) {
37             case -1: return -41;
38             default: return -3;
39             case -2: return 7;
40         }
41     }
42
43     public int runTest(int x) {
44         if (x >= 1000)
45             return fallsThrough (x);
46         else if (x >= 0)
47             return noDefault(x);
48         else
49             return oddDefault(x);
50     }
51 }
52
Popular Tags