Download presentation
Presentation is loading. Please wait.
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
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; }
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) { } else
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.