70 likes | 90 Vues
Seating “ chart ”. Front. 4 rows. 5 rows. 5 rows. 4 rows. 2 rows. 2 rows. 5 rows. 5 rows. 4 rows. Back. 10/17/2014. Switch Intro and a few odds and ends. Character data type explained. Characters take 2 bytes in memory Under the covers they are ints
E N D
Seating “chart” Front 4 rows 5 rows 5 rows 4 rows 2 rows 2 rows 5 rows 5 rows 4 rows Back
10/17/2014 Switch Intro and a few odds and ends
Character data type explained • Characters take 2 bytes in memory • Under the covers they are ints • Each int has a corresponding text symbol associated with it. • See CharDemo.java
Ints and doubles compared • Just like any other operation, relational operators can only operate on the same data type. • So in a mixed operation, Java will attempt to widen the operands so that they match one another. • See CharDemo.java
boolean data type • Variables of boolean type hold true or false. • We can declare variables of boolean and assign them values. • A boolean expression is anything that evaluates to true of false. A boolean expression must go in the parentheses of an if statement. • See CharDemo.java
Logic problems • Your cell phone rings. Return true if you should answer it. • Normally you answer, except in the morning you only answer if it is your mom calling. • In all cases, if you are asleep, you do not answer. • Answer demo
Switches • Given a value, choose from among many options. • Uses: • Menus • Options • Anything that has multiple discrete choices See SwitchDemo.java