001    /**
002     * Exercise 3.10 from the book
003     * 
004     * @author Kristian Torp, torp (at) cs (dot) aau (dot) dk
005     * @version 1.0
006     */
007    public class Exercise3_10 {
008            /**
009             * A switch statement with <code>break</code> statements.
010             */
011            public static void withBreaks() {
012                    System.out.println("With breaks");
013                    for (int i = 0; i <= 6; i++) {
014                            switch (i) {
015                            case 0:
016                                    System.out.println("zero");
017                                    break;
018                            case 1:
019                                    System.out.println("one");
020                                    break;
021                            case 2:
022                                    System.out.println("two");
023                                    break;
024                            case 3:
025                                    System.out.println("three");
026                                    break;
027                            case 4:
028                                    System.out.println("four");
029                                    break;
030                            case 5:
031                                    System.out.println("five");
032                                    break;
033                            default:
034                                    System.out.println("Bang");
035                            }
036                    }
037            }
038    
039            /**
040             * A switch statement without <code>break</code> statements.
041             */
042            public static void withoutBreaks() {
043                    System.out.println("Without breaks");
044                    for (int i = 0; i <= 6; i++) {
045                            switch (i) {
046                            case 0:
047                                    System.out.println("zero");
048                            case 1:
049                                    System.out.println("one");
050                            case 2:
051                                    System.out.println("two");
052                            case 3:
053                                    System.out.println("three");
054                            case 4:
055                                    System.out.println("four");
056                            case 5:
057                                    System.out.println("five");
058                            default:
059                                    System.out.println("Bang");
060                            }
061                    }
062            }
063    
064            /**
065             * The main method. Runs the two methods.
066             */
067            public static void main(String[] args) {
068                    withBreaks();
069                    withoutBreaks();
070            }
071    }
072