{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L3a Java Selection

L3a Java Selection - If/then/else JAVA SELECTION CONCEPTS...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
JAVA SELECTION CONCEPTS If/then/else
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background You should remember most of this stuff from your Programming Concepts class This is a brief review If/else in Java looks essentially identical to the same constructs in C. Most of the complexity of programs comes from the if statements, not the calculations (except for some scientific programs)
Background image of page 2
Independent if’s These may all be true, or none may be true Example: if ( a ) { System.out.println ( "a" ) ; } if ( b ) { System.out.println ( "b" ) ; }if ( c ) { System.out.println ( "c" ) ; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Mutually exclusive if’s One or another but not both can be true Example: if ( a ) { System.out.println ( "a" ) ; } else if ( b ) { System.out.println ( "b" ) ; }else if ( c ) { System.out.println ( "c" ) ; }
Background image of page 4
Mutually exclusive if’s (cont) Old school example if ( a ) { System.out.println ( "a" ) ; return ; } if ( b ) { System.out.println ( "b" ) ; return ; } if ( c ) { System.out.println ( "c" ) ; return ; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Switch statement Good for mutually exclusive decisions about the value of an integral type Example: switch ( v ) { case 'a' : System.out.println ( "a" ) ; break ; case 'b' : System.out.println ( "b" ) ;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}