Variables Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

An int always takes ___ bytes

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A fraction multiplied by an integer returns ____

A

zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To avoid truncation (operation using two integers)….

A

cast one of them to a double BEFORE the operation is applied (i.e. “a / (double) b” NOT “(double) (a/b)*. If at least one of the operands is a double, there is no need to cast the other one–it is promoted to a double automatically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Simply saying (1/2) will return what?

A
  1. This is because when one divides two integers, the resulting double is rounded DOWN to an integer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

== vs. .equals

A

== is true if and only if the two variables refer to exactly the same object (ADDRESSES). .equals compares the CONTENTS of the two objects (used for strings, primarily)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

De Morgan’s Laws

A

!(a && b) is the same as !a || !b

!(a || b ) is the same as !a && !b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Short-circuit evaluation

A

If the value of the first operand is sufficient to determine the result, then the second operand is NOT evaluated. For example:
int x = 0, y = 3;
String op = “/”
if (op.equals(“/”) && (x!= 0) && (y/x > 2)
do stuff
else
do other stuff

This code WILL compile and execute without error because although y/x is undefined, we never get that far b/c the second operand fails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly