1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 7 - Maria Litvin, Gary Litvin

30 24 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 30
Dung lượng 377,72 KB

Nội dung

Chapter 7 - Boolean expressions and if-else statements. This chapter also includes relational and logical operators, De Morgan’s Laws, the switch statement and enum data types. Another objective is to discuss team development and illustrate software reusability in the context of a simple but realistic case study, the Craps project.

Java Methods Object-Oriented Programming and Data Structures 2nd AP edition with GridWorld Maria Litvin ● Gary Litvin if (chapter == 7) Boolean Expressions and if-else Statements Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing All rights reserved Objectives: • Learn about the boolean data type • Learn the syntax for if-else statements • Learn about relational and logical operators, De Morgan’s laws, short-circuit evaluation • Learn when to use nested if-else statements, if-else-if sequences, the switch statement • Learn about enum data types 7­2 if-else Statement if ( ) { < statements > } else { < other statements > } if ( ) { < statements > } else clause is optional 7­3 boolean Data Type • George Boole (1815 - 1864) • boolean variables may have only two values, true or false • You define boolean fields or boolean local variables the same way as other variables private boolean hasMiddleName; boolean isRolling = false; boolean true false Reserved words 7­4 Boolean Expressions • In if ( ) is a Boolean expression • A Boolean expression evaluates to either true or false • Boolean expressions are written using boolean variables and relational and logical operators 7­5 Relational Operators , =, ==, != is equal to is NOT equal to 7­6 Relational Operators (cont’d) • Apply to numbers or chars: if ( count1 = numSlides) beep.play(); else slide++; } else { if (slide

Ngày đăng: 04/11/2020, 23:14

TỪ KHÓA LIÊN QUAN