Starting Out with Java: Early Objects, Student Value Edition (6th Edition)
Starting Out with Java: Early Objects, Student Value Edition (6th Edition)
6th Edition
ISBN: 9780134457918
Author: GADDIS, Tony
Publisher: PEARSON
Question
Book Icon
Chapter 4.6, Problem 4.16CP
Program Plan Intro

Logical operator:

Logical operators are used to validate an expression and return the Boolean values as “true” or “false”. Some of the logical operators are as follows:

  • Logical “and” operator
  • Logical “or” operator
  • The “not” operator

Logical “and” Operator:

Logical operator combines the results of one or more conditions.

  • The logical “and” is used to evaluate two expressions in order to obtain a single relational result.
  • It returns the Boolean value “True”, when both the operands are true, otherwise it returns “False”.
  • The first operand is evaluated first and all the side effects are completed before evaluating the logical “and” expression.
  • The second operand is evaluated only if the first operand is “True”.

Syntax for “and” operator:

The syntax for “and” operator is given below:

expression1 and expression2

Logical “or” Operator:

Logical operator combines the results of one or more conditions.

  • The logical “or” is used to evaluate two expressions in order to obtain a single relational result.
  • It returns the Boolean value “True” when one of the operands is “True”. It returns “false” only if both the operands are “false”.
  • The first operand is evaluated and all the effects are completed before it continues to evaluate the logical “or” expression.
  • The second operand is evaluated only if the first operands return “false”.

Syntax for “or” operator:

The syntax for “or” operator is given below:

expression1 or expression2

Logical “not” Operator:

The logical “not” operator is the unary operator that takes an operand and reverse its logical value.

Syntax for “not” operator:

!expression1

Blurred answer
Students have asked these similar questions
A. Modified TRUE of FALSE. Write T if the statement is TRUE and CHANGE the underlineword if the statement is FALSE._______________2. There is only one way to determine whether a business is going to be profitable or not.
Step 1:  Consider the following values set to variables. myAge = 32 yourAge = 18 myNumber = 81 yourNumber = 17 votingAge = 18 myName = “Katie” yourName = “Bob” Based on the values to the variables in Step 1, do the following conditions result in a true or false statement?  (Reference: Boolean Expressions, page 119).   The condition True or False myAge >= yourAge   yourAge > myAge   myAge == 45   yourAge == votingAge   votingAge <= yourAge   myAge <= votingAge   myName != yourName   myNumber <= myAge   yourNumber >= myAge   yourNumber != 17
1. Evaluate the expression below. Give the final result only (True or False). No need to show your solution. F || !(F && T || !F) && F  2. Give the valid relational expression for this statement: duration of game exceeds 30 minutes  3. Give the valid logical expression for this statement: fee is within 400 to 800

Chapter 4 Solutions

Starting Out with Java: Early Objects, Student Value Edition (6th Edition)

Ch. 4.2 - Write an if-else statement that assigns 0 to the...Ch. 4.4 - Write nested if statements that perform the...Ch. 4.4 - Write code that tests the variable x to determine...Ch. 4.5 - What will the following program display? public...Ch. 4.5 - The following program is used in a bookstore to...Ch. 4.6 - Prob. 4.16CPCh. 4.6 - Assume the variables a = 2, b = 4, and c = 6....Ch. 4.6 - Write an if statement that displays the message...Ch. 4.6 - Write an if statement that displays the message...Ch. 4.7 - Assume the variable name references a String...Ch. 4.7 - Prob. 4.21CPCh. 4.7 - Prob. 4.22CPCh. 4.9 - Rewrite the following if-else statements as...Ch. 4.10 - Complete the following program skeleton by writing...Ch. 4.10 - Rewrite the following if-else-if statement as a...Ch. 4.10 - Explain why you cannot convert the following...Ch. 4.10 - What is wrong with the following switch statement?...Ch. 4.10 - What will the following code display? int funny =...Ch. 4 - The if statement is an example of a __________. a....Ch. 4 - This type of expression has a value of either true...Ch. 4 - , , and = = are __________. a. relational...Ch. 4 - , | |, and ! are __________. a. relational...Ch. 4 - Prob. 5MCCh. 4 - To create a block of statements, you enclose the...Ch. 4 - This is a boolean variable that signals when some...Ch. 4 - How does the character A compare to the character...Ch. 4 - This is an if statement that appears inside...Ch. 4 - Prob. 10MCCh. 4 - When determining whether a number is inside a...Ch. 4 - Prob. 12MCCh. 4 - The conditional operator takes this many operands....Ch. 4 - This section of a switch statement is branched to...Ch. 4 - True or False: The = operator and the == operator...Ch. 4 - True or False: A conditionally executed statement...Ch. 4 - Prob. 17TFCh. 4 - True or False: When an if statement is nested in...Ch. 4 - True or False: When an if statement is nested in...Ch. 4 - True or False: The scope of a variable is limited...Ch. 4 - Find the errors in the following code: 1. //...Ch. 4 - Find the errors in the following code: 2. //...Ch. 4 - Find the errors in the following code: 3. //...Ch. 4 - Prob. 4FTECh. 4 - Find the errors in the following code: 5. The...Ch. 4 - Find the errors in the following code: 6. The...Ch. 4 - The following statement should determine whether...Ch. 4 - Find the errors in the following code: 8. The...Ch. 4 - Prob. 9FTECh. 4 - Write an if statement that assigns 100 to x when y...Ch. 4 - Write an if-else statement that assigns 0 to x...Ch. 4 - Using the following chart, write an if-else-if...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Write nested if statements that perform the...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if-else statement that displays the...Ch. 4 - Convert the following if-else-if statement into a...Ch. 4 - Match the conditional expression with the if-else...Ch. 4 - Explain what is meant by the phrase conditionally...Ch. 4 - Explain why a misplaced semicolon can cause an if...Ch. 4 - Why is it good advice to indent all the statements...Ch. 4 - What happens when you compare two String objects...Ch. 4 - Prob. 5SACh. 4 - What risk does a programmer take when not placing...Ch. 4 - Prob. 7SACh. 4 - Prob. 8SACh. 4 - Why are the relational operators called...Ch. 4 - How do you use private methods in a class to...Ch. 4 - Roman Numerals Write a program that prompts the...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - TestScores Class Design a TestScores class that...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - BankCharges Class A bank charges 10 per month,...Ch. 4 - ShippingCharges Class The Fast Freight Shipping...Ch. 4 - FatGram Class Design a class with a method that...Ch. 4 - Running the Race Write a program that asks for the...Ch. 4 - The Speed of Sound The following table shows the...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Mobile Service Provider A mobile phone service...Ch. 4 - Mobile Service Provider, Part 2 Modify the program...Ch. 4 - Body Mass Index Write a program that calculates...Ch. 4 - Days in a Month Write a class named MonthDays. The...Ch. 4 - Book Club Points Serendipity Booksellers has a...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Hot Dog Cookout Calculator Assume that hot dogs...Ch. 4 - Roulette Wheel Colors On a roulette wheel, the...Ch. 4 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 4 - Restaurant Selector You have a group of friends...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Oracle 12c: SQL
Computer Science
ISBN:9781305251038
Author:Joan Casteel
Publisher:Cengage Learning