Lecture Fundamentals of computing 1: Lecture 4 - Duy Tan University

Lecture Fundamentals of computing 1: Lecture 4 introduce the conditional expression. This chapter presents the following content: The if statements, the if/else statements, the switch statements. | Lecture Title: Conditional Expression Fundamentals of Computing 1 Agenda The if statements The if/else statements The switch statements ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) The if statement Executes a block of statements only if a test is true if (test) { statement; . statement; } Example: Agenda The if statements The if/else statements The switch statements ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) The if/else statement Executes one block if a test is true, another if false if (test) { statement(s); } else { statement(s); } Example: Relational expressions Tests use relational operators: Operator Meaning Example Value == equals 1 + 1 == 2 true != does not equal != true greater than 10 > 5 true = greater than or equal to >= true Note that == tests equality, not = . The = is used for the assignment operator! Misuse of if Scanner console = new Scanner(); ("What percentage did you earn? "); int percent = (); if (percent >= 90) { ("You got an A!"); } if (percent >= 80) { ("You got a B!"); } if (percent >= 70) { ("You got a C!"); } if (percent >= 60) { ("You got a D!"); } if (percent 0) { ("Positive"); } else if (x Nested if/else/if If it ends with else, exactly one path must be taken. If it ends with if, the code might not execute any path. if (test) { statement(s); } else if (test) { statement(s); } else if (test) { statement(s); } . | Lecture Title: Conditional Expression Fundamentals of Computing 1 Agenda The if statements The if/else statements The switch statements ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) The if statement Executes a block of statements only if a test is true if (test) { statement; . statement; } Example: Agenda The if statements The if/else statements The switch statements ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) The if/else statement Executes one block if a test is true, another if false if (test) { statement(s); } else { statement(s); } Example: Relational expressions Tests use relational operators: Operator Meaning Example Value == equals 1 + 1 == 2 true != does not equal != true greater than 10 > 5 true = greater than or equal to >= true Note that == tests equality, not = . .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
185    463    14    28-04-2024
164    63    2    28-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.