<< Chapter < Page Chapter >> Page >

Not the same as rounding

If each of the values assigned to the variables named w and x in this program were rounded to the nearest integer, the result would be 4 and -4, not 3 and -3as produced by the program.

Back to Question 5

Answer 4

A. Compiler Error

Explanation 4

Cannot cast a boolean type

A boolean type cannot be cast to any other type. This program produces the following compiler error:

Ap042.java:13: inconvertible types found : booleanrequired: int int y = (int)x;

Back to Question 4

Answer 3

D. B

Explanation 3

The logical and operator

The logical and operator shown below

The logical and operator &&

performs an and operation between its two operands, both of which must be of type boolean . If both operands are true, the operator returns true. Otherwise, it returns false.

The boolean negation operator

The boolean negation operator shown below

The boolean negation operator

!

is a unary operator, meaning that it always has only one operand. That operand must be of type boolean , and the operand always appears immediately to the right of the operator.

The behavior of this operator is to change its right operand from true to false, or from false to true.

Evaluation from left to right

Now, consider the following code fragment from this program.

int x = 5, y = 6; if(!(x<y)&&!(y<x/0)){ System.out.println("A");}else{ System.out.println("B");}//end else

The individual operands of the logical and operator are evaluated from left to right.

Consider the left operand of the logical and operator that reads:

!(x<y)

The following expression is true

(x<y)

In this case, x is less than y , so the expression inside the parentheses evaluates to true.

The following expression is false

!(x<y)

The true result becomes the right operand for the boolean negation operator at this point.

You might think of the state of the evaluation process at this point as being something like

not true .

When the ! operator is applied to the true result, the combination of the two become a false result.

Short-circuit evaluation applies

This, in turn, causes the left operand of the logical and operator to be false .

At that point, the final outcome of the logical expression has been determined. It doesn't matter whether the right operand is true or false. Thefinal result will be false regardless.

No attempt is made to evaluate the right operand

Therefore, no attempt is made to evaluate the right operand of the logical and operator in this case.

No attempt is made to divide the integer variable x by zero, no exception is thrown, and the program doesn't terminate abnormally. It runs to completion anddisplays a B on the screen.

Back to Question 3

Answer 2

C. A

Explanation 2

Short-circuit evaluation

Question 1 was intended to set the stage for this question.

This Question, in combination with Question 1 , is intended to help you understand and remember the concept of short-circuit evaluation.

What is short-circuit evaluation?

Logical expressions are evaluated from left to right. That is, the left operand of a logical operator is evaluated before the right operand of the sameoperator is evaluated.

Questions & Answers

what is demand
Joseph Reply
Demand simply refers to the amount of goods and services which the consumer is willing and able to purchase at each price
Owusu
what is mean by unitary elastic demand
Bangniyel Reply
demand is said to be unitary elastic when the percentage change in the demand is equal to the percentage change in the price
George
what is the principle of equi-marginal utility
Reliance Reply
what is Economics and it important
Anita Reply
what is production
Anita
what is Economic
Anita Reply
what is the meaning of Economic
Anita
economics is a science which studies human behaviour as a relationship between ends and scarce means which have alternative uses
Boso
I don't know.
natchanan
u don't
Ssali
@ Boso thanks for the definition ✌
Raewyn
boso u r too much u try
Liambee
ya nyc
Ssali
Thanks kk
Anita
pls can I ask more questions
Anita
what is production
Anita
production is creation of goods and services
George
what is macroeconomics and microeconomics
Anita
macroeconomics deals with larger economic units such as GDP,GNP,employment while microeconomics deals with smaller economic units such firm and household
George
Thanks
Anita
Explain the ff Scarcity Ends Demand Supply Choice Scale of preference
Anita
macroeconomics deals with larger economic units such as GDP,GNP,employment while microeconomics deals with smaller economic units such firm and household
George
Gross Domestic product...it represent the total value of the products produced within the country including foreign industries
George Reply
what is products
Anita
what are the favourable demand
Odia Reply
list of climate that affect demands
Odia
What is two major forms of international trade?
Musa Reply
What is Economics and why it is important
Abdul Reply
De ans,Economics is the study of women behavior as a relationship between end and scared mean which have alternative uses.
Anita
What is Inflation
Abdul Reply
More money = more consumers, more consumers = lessen the product, less product = high price, high price = inflation
TuroN
is it definition
Odia
why price and quantity increase
Otuu Reply
condition under which price and quantity will be increased at the same time
Otuu
factors that hinders mobility of labour
Dennis Reply
what is scarcity
Adams Reply
why are people still unemployed in this economy we live in
Joyce Reply
why are people still unemployed in this economy
Joyce
Because of high technology
Innocent
Due to low government expenditure, the state does not have money to invest in new projects that can result in more job opportunities.
Young
good afternoon all, what are the examples of development projects Pls?
James
I 'm not together with him, when we say government expenditure mean there is recession for her economic country. That why many people still unemployed in this economy we live in, it mainly depend for two phases like Natural hazards and human activities.
Innocent
For the first answer I was responded we are concerns to intensive technology in the whole world it lead to reduce of many workers.
Innocent
wat does the abbreviation ppc mean?
Tumiso
I would like to give you ideas so that you get well how can give answer to this question dears. Attempt to know these words and what these means; Deficit, Surplus and Balanced budget.
Innocent
ppc mean pay -per-click known as search engine marketing
Innocent
i found it ppc means production possibility curve
Tumiso
in economic is that true according to your answer, however about of Marketing is that Pay Per Click.
Innocent
how is inflation, output gap relate to monetary policy
Mary Reply
Difference between extinct and extici spicies
Amanpreet Reply
While the American heart association suggests that meditation might be used in conjunction with more traditional treatments as a way to manage hypertension
Beverly Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask