1 / 9

Announcements

Announcements. Quiz 1 Posted on blackboard Quiz 1 Handed Back (and Gone Over) Next Monday “Just a Quiz” 5% of Final Grade Exam 1 is 10% of Final Grade. Selection (if-then-else). Programming Has 3 Types of Control: Sequential (normal) : Control of Execution Proceeds One after the Other

dmeza
Download Presentation

Announcements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Announcements • Quiz 1 Posted on blackboard • Quiz 1 Handed Back (and Gone Over) Next Monday • “Just a Quiz” • 5% of Final Grade • Exam 1 is 10% of Final Grade

  2. Selection (if-then-else) • Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else): Control Proceeds Dependent on Conditions Iteration (looping): Control Repeated until Condition Met

  3. JAVA if Statement Syntax • Syntax if (condition)statement; • If Condition Is True, Statement Is Executed • If Condition Is False, Statement Is Not Executed • If Multiple Actions Are Required for Statement, a Compound Statement Must Be Used: if (condition) { statement; statement; }

  4. Conditional Operators • Relational Operators: < , > , >= , <= • Equality Operators: == , !=

  5. Comparing Strings • Cannot use Equality Operators • Use .equals() instead: String myString; … if (myString.equals(“Hello”) ) System.out.println(“Well, Hello to you too!!”);

  6. Selection Examples int age; char grade; String firstName; //Code to assign to age, grade, and firstName if (age < 30) System.out.println( “You are very very Young”); if (grade == ‘A’) System.out.println(“Congratulations!” ); if (grade != ‘F’) System.out.println(“You passed!” ); if (firstName.equals(“Jon”)) System.out.println(“Thanks, Jon!” );

  7. else Statement • Syntax: • if (condition) • { • statement(s);//condition true • } • else • { • statement(s);//condition false • }

  8. if-else Example • if (myGrade >= 60) • { • System.out.println(“You passed!” ); • } • else • { • System.out.println(“How about them Cubs?” ); • }

  9. Compound Statements • Compound Statement: One or More Statements within a Set of Curly Braces • Must Use Compound Statement if More than One Statement Is Supposed to be under Control of if or else Conditional • Include Curly Braces after if so if other Statements Are Added in Future, Curly Braces Are Already There

More Related