



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information on the ternary operator, switch statement, break, and continue in java programming. It includes explanations, examples, and warnings about method overloading and implicit widening conversions. It is taken from the cmsc 131 fall 2006 and 2007 lecture notes.
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




CMSC 131 Fall 2006 Jan Plane (adapted from Bonnie Dorr)
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
1
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
2
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
3
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
6
The control expression can have one of the following types: char, int, short, byte not float, double, boolean, long not a String or other object Case continuation also called “cascading case behavior”, “falling through to the next case”, etc.
It is occasionally handy for combining of cases e.g. case-insensitivity switch (grade) { case ‘a’: case ‘A’: System.out.println (“I’m very happy”); break; … }
Be very careful about using this cascading behavior!
Always insert break statements after every case Then remove ones you do not want
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
7
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
8
break can also be used to exit immediately from any loop
while do-while for
e.g. “Read numbers from input until negative number encountered” Scanner sc = new Scanner (System.in); int n; while (true) { n = sc.nextInt (); if (n < 0) break; else
CMSC 131 Fall 2007 Jan Plane (adapted from Bonnie Dorr)
9