Danh mục

Java Programming for absolute beginner- P6

Số trang: 20      Loại file: pdf      Dung lượng: 487.24 KB      Lượt xem: 18      Lượt tải: 0    
Thư Viện Số

Hỗ trợ phí lưu trữ khi tải xuống: 7,000 VND Tải xuống file đầy đủ (20 trang) 0

Báo xấu

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Programming for absolute beginner- P6:Hello and welcome to Java Programming for the Absolute Beginner. You probablyalready have a good understanding of how to use your computer.These days it’s hard to find someone who doesn’t, given the importanceof computers in today’s world. Learning to control your computer intimatelyis what will separate you from the pack! By reading this book, you learnhow to accomplish just that through the magic of programming.
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P6 JavaProgAbsBeg-03.qxd 2/25/03 8:49 AM Page 78 78 Java Programming for the Absolute Beginner FIGURE 3.10 This is several runs of the HighOrLowTemp program. Nesting if-else Structures So far, you are able to conditionally execute one of two statements based on a sin- gle condition. Sometimes you need to have more than two branches in the flow of your program based on a set of related conditions. This is possible in Java. You know that in the if-else structure, the statement (any valid Java statement) that the program executes if the condition is false follows the else keyword. The key here is any valid Java statement—including another conditional statement. These types of structures are called nested if-else statements. Take a look at the syntax: if (condition1) { java_statements_for_true_condition1; } else if (condition2) { java_statements_for_true_condition2; } else { java_statements_for_false_conditions; } If condition1 is true, the program executes java_statements_for_true_condi- tion1. If condition1 is false, condition2 is tested. You do this by immediately fol- lowing the else keyword with another if conditional statement. If condition2 is true, the program executes java_statements_for_true_condition2. Finally, if neither condition is true the java_statements_for_false_conditions are exe- cuted. Take a look at this quick example, and then move on to the next section where you use apply this concept in an actual program: if (name == “Joseph”) { System.out.println(name + “ is my first name.”); } else if (name == “Russell”) { System.out.println(name + “ is my last name.”); } else { System.out.println(name + “ is not my name.”); } TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-03.qxd 2/25/03 8:49 AM Page 79 79 Assume that name is a string holding some person’s name. This snippet of code indicates that the name is my first name if it is “Joseph“, else if it is “Russell“, Chapter 3 the code indicat ...

Tài liệu được xem nhiều: