Chapter 2 Flashcards

1
Q

What is x after the following statements?
int x = 1;
x *= x + 1;

A

x is 2.

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

To assign a value 1 to variable x, you write

A

x = 1;

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

What is the exact output of the following code?
double area = 3.5;
System.out.print(“area”);
System.out.print(area);

A

area3.5

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

Suppose x is 1. What is x after x -= 1?

A

0

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

The __________ method returns a raised to the power of b.

A

Math.pow(a, b)

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

Suppose x is 1. What is x after x += 2?

A

3

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

___________ is the Java assignment operator.

A

=

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

Which of these data types requires the most amount of memory?

A

long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Which of the following is incorrect?
int x = 9;
long x = 9;
float x = 1.0;
double x = 1.0;
A

float x = 1.0;

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

What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;

A

x is 4.

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

If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value.

A

double

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

What is the value of (double)5/2?

A

2.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
According to Java naming convention, which of the following names can be variables?
FindArea
findArea
totalLength
TOTAL_LENGTH
class
A

totalLength

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

Which of the following is a constant, according to Java naming conventions?
MAX_VALUE

Test

read

ReadInt

COUNT

A

MAX_VALUE

COUNT

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

-25 % 5 is _____

A

0

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

Which of the following are correct ways to declare variables?Which of the following are correct ways to declare variables?

int length; int width;

int length, width;

int length; width;

int length, int width;

A

int length, width;

17
Q

Which of the following assignment statements is incorrect?

i = j = k = 1;
i = 1; j = 1; k = 1;
i = 1 = j = 1 = k = 1;
i == j == k == 1;

A

i == j == k == 1;

18
Q

What is the result of 45 / 4?

A

11

19
Q

To assign a double variable d to a float variable x, you write

A

x = (float)d;

20
Q

Every letter in a Java keyword is in lowercase?

A

true