CC2203-les01javaI-for-Viewing-1011s2

CC2203-les01javaI-for-Viewing-1011s2 - 1-1/25Lesson 1: Java...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1-1/25Lesson 1: Java I – Flow Control and ExceptionsAfter completing this lesson, you should be able to do the following:•Use decision-making constructs•Perform loop operations•Explain the basic concepts of exception handling1-2/25Categorizing Basic Flow Control TypesFlow control can be categorized into four types:SequentialTransferSelectionIteration1-3/25Using Flow Control in Java•Each simple statement terminates with a semicolon (;).•Group statements by using the braces { }.•Each block executes as a single statement within the flow of control structure.{boolean finished = true;System.out.println("i = " + i);i++;}1-4/25Using the ifStatementif ( boolean_expr )statement1;[elsestatement2];if (i % 2 == 0)System.out.println("Even");elseSystem.out.println("Odd");…if (i % 2 == 0) {System.out.print(i);System.out.println(" is even");}General :Examples:1-5/25Nesting ifStatementsif (speed >= 25)if (speed > 65)System.out.println("Speed over 65");elseSystem.out.println("Speed greater than or equal to 25 but less than or equal to 65");elseSystem.out.println("Speed under 25");if (speed > 65)System.out.println("Speed over 65");else if (speed >= 25)System.out.println("Speed greater… to 65");elseSystem.out.println("Speed under 25");[Demonstration - JavaI.zip]1-6/25Defining the switchStatement•Useful to select from several alternative integer values•Constant_exprsmust be byte, int, char,or short.switch ( integer_expr ) {case constant_expr1:statement1;break;case constant_expr2:statement2;break;[default:statement3;]}1-7/25More About the switchStatement•Case labels must be constants....
View Full Document

This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.

Page1 / 25

CC2203-les01javaI-for-Viewing-1011s2 - 1-1/25Lesson 1: Java...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online