CS180 Chapter 3 Quiz Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000

((x > 500 && x < 650) || (y != 1000))

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;

0.0

What is the value of ans after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x < y) ans += y;

100

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

1000

What will be the value of x after the following statements are executed? int x = 75; int y = 60; if (x > y) x = x - y;

15

What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;

165

int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) *payRate * 1.5;

475

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x = 0, y = 50

A block of code is enclosed in a set of

braces { }

Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'? Select one: A. chrA != 'A' B. chrA == 'A' C. chrA.notEquals(A) D. chrA || 'A'

chrA != 'A'

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?

if (temp >= 0 && temp <= 100)

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10;

no value, this is a syntax error

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

str1.equalsIgnoreCase(str2)

In an if-else statement, if the boolean expression is false then

the statement or block following the else statement is executed

The boolean expression in an if statement must evaluate to

true or false


Kaugnay na mga set ng pag-aaral

Chapter 11 Stress Psychology 2301

View Set

MacroEconomics 10.3 Long-Run Equilibrium and the Price Level

View Set

SAS Programming II Business Analysis Applications - C748

View Set

Multiplying Fractions & Whole Numbers

View Set

Chapter 2 The Enlightenment and the American Revolution

View Set

Childbirth at Risk and Birth-Related Procedures

View Set