WSSU Java Quiz 3 - IF Statements

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

3. What will be the output of the following code? int num = 10; if(num < 0) { num = num + 5; num++; } System.out.print(num); a. 10 b. 11 c. 16 d. none of these

ANS: A

10. What is the value of entry after the following statements are executed? int entry = 9, number = 3; if ((entry > 9) || (entry/number == 3)) { entry--; } else if (entry == 9) { entry++; } else { entry = 3; } a. 3 c. 9 b. 8 d. 10

ANS: B

4. What will be the output of the following code? int num = 10; if(num < 0) num = num + 5; num++; System.out.print(num); a. 10 b. 11 c. 16 d. none of these

ANS: B

8. What would be the value of bonus after the following statements are executed? int bonus, sales = 1000; if (sales > 1000) { bonus = 100; } else if (sales > 750) { bonus = 50; } else if (sales > 500) { bonus = 25; } else { bonus = 0; } a. 100 b. 50 c. 25 d. 0

ANS: B

11. What will be the output of this code? int grade = 95; String letterGrade = "C"; if (grade < 90) if (grade >= 80) letterGrade = "B"; else letterGrade = "A"; System.out.println(letterGrade); a. A b. B c. C d. none of these

ANS: C

13. What is the value of the variable named counter after the statements that follow are executed? double percent = 0.54; boolean valid = true; int counter = 1; if ((percent > 0.50) && (valid == true)) { counter += 2; if (valid == true) counter++; else if (percent >= 0.50) counter += 3; } else { counter++; } a. 2 c. 4 b. 3 d. 7

ANS: C

14. What is the output of the following code? int k = 4, j = 10; if ((k < 7) && (j < 10)) { if (k + j < 20) { System.out.println("A grade"); } else { System.out.println ("B grade"); } } else { if (k + j < 20) { System.out.println ("C grade"); } else { System.out.println ("D grade"); } } a. A grade c. C grade b. B grade d. D grade

ANS: C

2. 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? a. ((x >= 500 && x <= 650) && (y != 1000)) b. ((x > 500 && x < 650) || !(y.equal(1000))) c. ((x > 500 && x < 650) || (y != 1000)) d. ((x < 500 && x > 650) || !(y == 1000))

ANS: C

5. What will be the output of the following code? int num = - 10; if(num > 0) { num = num + 5; } else { num = num - 5; num--; } System.out.print(num); a. -10 b. -15 c. -16 d. none of these

ANS: C

9. What would be the value of bonus after the following statements are executed? int bonus, sales = 1000; if (sales > 1000) { bonus = 100; } if (sales > 750) { bonus = 50; } if (sales > 500) { bonus = 25; } else { bonus = 0; } a. 100 b. 500 c. 25 d. 0

ANS: C

1. If chr is a character variable, which of the following if statements is written correctly? a. if (chr = "a") System.out.print("true"); b. if (chr == "a") System.out.print("true"); c. if (chr = 'a') System.out.print("true"); d. if (chr == 'a') System.out.print("true");

ANS: D

12. What would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 100000) { if (dept == 'R') { bonus = 2000; } else { bonus = 1500; } } else if (sales > 75000) { if (dept == 'R') { bonus = 1250; } else { bonus = 1000; } } else { bonus = 0; } a. 2000 b. 1500 c. 1250 d. 1000

ANS: D

7. What will be the value of bonus after the following code is 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; } a. 200 b. 500 c. 750 d. 1000 e. 1250

ANS: D

6. What will be the output of the following code? int num = 10; if(num > 0) num = num + 5; else num = num - 5; num--; System.out.print(num); a. -10 b. -15 c. -16 d. none of these

ANS: D (the output will be 14. Think why.)


Kaugnay na mga set ng pag-aaral

CS61: Introduction to Computing Systems

View Set

Chronic PrepU- Ch. 55 Urinary Disorders

View Set

Chapter 1 Intermediate Accounting

View Set