TAILIEUCHUNG - 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); } .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.