intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Lecture Java programming language: Conditional Control Structures - Ho Dac Hung

Chia sẻ: Trinh _ | Ngày: | Loại File: PDF | Số trang:11

49
lượt xem
1
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Lecture Java programming language: Conditional Control Structures introduces content such as the if Statement , the if-else statement, nested statements, the if-else if statement, the switch statement, generating random number, compound boolean expressions, the math class.

Chủ đề:
Lưu

Nội dung Text: Lecture Java programming language: Conditional Control Structures - Ho Dac Hung

  1. Conditional Control Structures Ho Dac Hung 1
  2. The if Statement  The if statement is a conditional control structure, also called a decision structure, which executes a set of statements when a condition is true. Conditional control structures are used to change program flow. The if statement takes the form: if(
  3. The if Statement  The condition of an if statement is a boolean expression, which evaluates to either true or false. Relational operators can be used to form boolean expression. ==, =, != 3
  4. The if-else Statement  The if statement can include an optional else clase that is executed when the if conditon evaluates to false. The if-else statement takes the following form: if (){ } else { } 4
  5. Nested Statements  An if-else statement can contain another if-else or if statement. Statement placed within the same type of statememts are called nested. 5
  6. The if-else if Statement  The if-else if statement is used to decide among three or more actions and take the form: if (){ } else if (){ } else { } 6
  7. The switch Statement  The switch statement is a conditional control structure that uses the result of an expression to determine which statements to execute. The switch statement takes the form: switch (){ case x: break; … default: 7 }
  8. Generating Random Number  Generating a series of random numbers is one of those common tasks that crops up from time to time. In Java, it can be achieved simply by using the java.util.Random class. 8
  9. Generating Random Number  nextBoolean()  nextDouble()  nextFloat()  nextInt()  nextLong() 9
  10. Compound Boolean Expressions  Conditions with complex criteria are formed using the && and || operators.  How a compound boolean expression evaluates with && and || operators can be shown with truth tables. 10
  11. The Math Class  Java includes the Math class in the java.lang package for performing math functions. abs pow sqrt floor ceil sin cos tan 11 …
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2