Chapter 16 JAVA Flashcards

1
Q

How many choices are possible when using a single if-else statement?

A. 1

B. 2

C. 3

D. 4

A

B. 2

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

What does the following code fragment write to the monitor?

int sum = 14;
if ( sum < 20 )
  System.out.print("Under ");
else
{  
  System.out.print("Over  ");
  System.out.println("the limit.");
}

A. Under

B. Over

C. Under the limit.

D. Over the limit.

A

A. Under

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

What does the following code fragment write to the monitor?

int sum = 14;
if ( sum < 20 )
  System.out.print("Under ");
else
{  
  System.out.print("Over  ");
  System.out.println("the limit.");
}

A. Under

B. Over

C. Under the limit.

D. Over the limit.

A

A. Under

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

What does the following code fragment write to the monitor?

int sum =  7; 
if ( sum > 20 )
{
  System.out.print("You win ");
}
else
{
  System.out.print("You lose  ");
}

System.out.println(“the prize.”);

A. You win

B. You lose

C. You win the prize.

D. You lose the prize.

A

D. You lose the prize.

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

What does the following code fragment write to the monitor?

int sum =  21; 
if ( sum != 20 )
  System.out.print("You win ");
else
  System.out.print("You lose  ");

System.out.println(“the prize.”);

(Notice that the program has changed from the previous question!)

A. You win

B. You lose

C. You win the prize.

D. You lose the prize.

A

C. You win the prize.

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

Evaluate (to true or false) each of the following expressions:

14 <= 14 14 < 14 -9 > -25 -25 > -9
A. true true true true

B. true false false false

C. true false true true

D. true false true false

A

D. true false true false

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

What does the following code fragment write to the monitor?

int roll = 13;

if ( roll > 20 )
  System.out.println("Jackpot!");
else
{
  if ( roll < 10 )
     System.out.print("You lose ");
  else
     System.out.print("You win ");
  System.out.println("the prize.");
}

A. Jackpot!

B. You lose

C. You win

D. You win the prize.

A

D. You win the prize.

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

What does the following code fragment write to the monitor?

int temp = 62;

if ( temp > 60 )
{
  if ( temp > 80 )
     System.out.println("Hot");
  else
     System.out.println("Moderate");
}
else
  System.out.print("Chilly");

A. Hot

B. Moderate

C. Chilly

D. Nothing is printed

A

B. Moderate

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

What does the following code fragment write to the monitor?

int temp = 32;

if ( temp >= 60 )
{
  if ( temp >= 80 )
     System.out.println("Hot");
  else
     System.out.println("Moderate");
}
else
{
  if ( temp >= 40 )
     System.out.println("Chilly");
  else
     System.out.println("Frigid");
}

A. Hot

B. Moderate

C. Chilly

D. Frigid

A

D. Frigid

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

What does the following code fragment write to the monitor?

int temp = 40; // Note change

if ( temp >= 60 )
{
  if ( temp >= 80 )
     System.out.println("Hot");
  else
     System.out.println("Moderate");
}
else
{
  if ( temp >= 40 )
     System.out.println("Chilly");
  else
     System.out.println("Frigid");
}

A. Hot

B. Moderate

C. Chilly

D. Frigid

A

C. Chilly

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

What does the following code fragment write to the monitor?

int score = 82;

if ( score >= 80 )
{
  if ( score >= 90 )
     System.out.println("A");
  else
     System.out.println("B");
}
else
{
  if ( score >= 70 )
     System.out.println("C");
  else
     System.out.println("D");
}

A. A

B. B

C. C

D. D

A

B. B

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