Test 1 Flashcards

(19 cards)

1
Q

Which of the following code displays the area of a circle if the radius is positive?

A

if (radius > 0) System.out.println(radius * radius * 3.14159);

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

Suppose income is 4001, what is the output of the following code?
if (income > 3000) {
System.out.println(“Income is greater than 3000”);}
else if (income > 4000) {
System.out.println(“Income is greater than 4000”);}

A

Income is greater than 3000

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

Analyze the following code.
int x = 0;
if (x > 0); {
System.out.println(“x”);
}

A

The symbol x is always printed.

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

The following code displays ___________.
double temperature = 50;
if (temperature >= 100) System.out.println(“too hot”);
else if (temperature <= 40) System.out.println(“too cold”);
else System.out.println(“just right”);

A

just right

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

The extension name of a Java source code file is:

A

java

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

Suppose you write the code to display “Cannot get a driver’s license” if age is less than 16 and “Can get a driver’s license” if age is greater than or equal to 16. Which of the following code is the best?

A

if (age < 16) System.out.println(“Cannot get a driver’s license”);
else System.out.println(“Can get a driver’s license”);

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

What is the printout of the following code fragment?
double x = 5.5;
int y = (int)x;
System.out.println(“x is “ + x + “ and y is “ + y) ;

A

x is 5.5 and y is 5

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

Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?
if (x > 0)
if (y > 0)
System.out.println(“x > 0 and y > 0”);
else if (z > 0)
System.out.println(“x < 0 and z > 0”);

A

x < 0 and z > 0

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

Which of the following assignment statements is illegal?

A

int t = 4.5;

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

If a program compiles fine, but it produces incorrect result, then the program suffers __________.

A

logical error

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

The expression “Java “ + 1 + 2 + 3 evaluates to ________.

A

Java 123

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.0

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

What is the printout of the following code?
double x = 10.1;
int y = (int)x;
System.out.println(“x is “ + x + “ and y is “ + y);

A

x is 10.1 and y is 10

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

Analyze the following code:
if (x < 100) && (x > 10)
System.out.println(“x is between 10 and 100”);

A

The statement has compile errors because (x<100) && (x > 10) must be enclosed inside parentheses.

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

Suppose s is a string with the value “program”, char x = s.charAt(4) will return __________.

A

‘r’

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

To assign a double variable d to an int variable x, you write

17
Q

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

18
Q

Analyze the following code.
boolean even = false;
if (even) { System.out.println(“It is even!”);}

A

The code displays nothing.

19
Q

What method do you use to read an int value?

A

input.nextInt();