# 7.4 Ap0040: self-assessment, logical operations, numeric casting,  (Page 7/8)

 Page 7 / 8

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.

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;```

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

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

The following expression is true

 `(x

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

The following expression is false

 `!(x

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.

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.

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
how can I make nanorobot?
Lily
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
Got questions? Join the online conversation and get instant answers!