<< 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:


The following expression is true


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

The following expression is false


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

I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
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?