COMP 110 CONDITIONALS Instructor Prasun Dewan PREREQUISITE Types
- Slides: 14
COMP 110 CONDITIONALS Instructor: Prasun Dewan
PREREQUISITE Types Math . 2
CONDITIONALS print. Pass. Fail. Status(95) Passed print. Pass. Fail. Status(25) Failed public static void print. Pass. Fail. Status(int score) { if (score < PASS_CUTOFF) System. out. println("FAILED"); else System. out. println("PASSED"); } 3
IF-ELSE STATEMENT if ( <boolean expression> ) <statement 1>; else <statement 2>; 4
IF-ELSE STATEMENT true <statement 1> <boolean expression> false <statement 2> 5
COMPOUND STATEMENT public void fancy. Print. Grade(int score) { if (score < PASS_CUTOFF) { System. out. println("*******"); System. out. println("FAILED"); System. out. println("*******"); } else { System. out. println("*******"); System. out. println("PASSED"); System. out. println("Congratulations!"); System. out. println("*******"); } } 6
COMPOUND STATEMENT – { }CONVENTION public void fancy. Print. Grade(int score) { if (score < PASS_CUTOFF) { System. out. println("*******"); System. out. println("FAILED"); System. out. println("*******"); } else { System. out. println("*******"); System. out. println("PASSED"); System. out. println("Congratulations!"); System. out. println("*******"); } } 7
AVOIDING CODE DUPLICATION IN IF-ELSE (EDIT) public void fancy. Print. Grade(int score) { if (score < PASS_CUTOFF) { System. out. println("*******"); System. out. println("FAILED"); System. out. println("*******"); } else { System. out. println("*******"); System. out. println("PASSED"); System. out. println("Congratulations!"); System. out. println("*******"); } } 8
AVOIDING CODE DUPLICATION IN IF-ELSE public void fancy. Print. Grade(int score) { System. out. println("*******"); if (score < PASS_CUTOFF) System. out. println("FAILED"); else { System. out. println("PASSED"); System. out. println("Congratulations!"); } System. out. println("*******"); } 9
IF STATEMENT if (score == MAX_SCORE) System. out. println ("Perfect Score! Congratulations!"); if (<bool expr>) <statement>; 10
IF STATEMENT true <statement 1> <boolean expression> false 11
ELSE-IF public static char to. Letter. Grade (int score) { if (score >= A_CUTOFF) return 'A'; else if (score >= B_CUTOFF) return 'B'; else if (score >= C_CUTOFF) return 'C'; else if (score >= D_CUTOFF) return 'D'; else return 'F'; } 12
NESTED IF-ELSE if (score >= A_CUTOFF) return 'A'; else if (score >= B_CUTOFF) return 'B'; else if (score >= C_CUTOFF) return 'C'; else if (score >= D_CUTOFF) return 'D'; else return 'F'; 13
NESTED IF-ELSE 14
- Prasun dewan
- Prasun dewan
- Numero niss
- 000 111 000
- Eecs 110
- Four types of conditionals
- Conditional sentence type 0 1
- Chain poem using conditionals
- Prerequisite program for haccp
- 7 key principles of haccp
- Definition group discussion
- Prerequisite program template
- Ics 31 credit by exam
- Uci ap scores
- Prerequisites in performance management process