TAILIEUCHUNG - Java Programming for absolute beginner- P6

Java Programming for absolute beginner- P6:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | 2 25 03 8 49 AM Page 78 78 Java Programming for the Absolute Beginner FIGURE 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 single 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 conditionl java_statements_for_true_condition1 else if condition java_statements_for_true_condition2 else java_statements_for_false_conditions If conditionl is true the program executes java_statements_for_true_condi-tionl. If conditionl is false conditiond is tested. You do this by immediately following 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 executed. 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 name is my first name. else if name Russell name is my last name. else name is not my name. team Line - live informative Non-cost and Genuine Please purchase PDF Split-Merge on to remove this watermark. 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 the code indicates that it is my last name. If it is neither my first name nor my last name

TÀI LIỆU XEM NHIỀU
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG