ITP 120 - Chapter 3 Part 2 QUIZ
Which one of the following is the not equal operator?
!=
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 bonus after the following code is executed? int bonus, sales = 100000; 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 printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x);
45,678.26
Which of the following will format 12.7801 to display as $12.78?
System.out.printf("$%,.2f", 12.7801);
Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?
if (chr != 'B')
What will be printed when the following code is executed? double x = 45678.259; String output = String.format("%,.1f", x); System.out.println(output);
45,678.3
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?
((x <= 500 || x > 650) && !(y == 1000))
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; if (purchase > 1000) discountRate = .05; if (purchase > 750) discountRate = .03; if (purchase > 500) discountRate = .01; else discountRate = 0;
.01
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = .05; else discountRate = .04; else if (purchase > 750) if (cust == 'Y') discountRate = .04; else discountRate = .03; else discountRate = 0;
.04
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = .05; else if (purchase > 750) discountRate = .03; else if (purchase > 500) discountRate = .01;
0.0
What would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 10000) if (dept == 'R') bonus = 2000; else bonus = 1500; else if (sales > 75000) if (dept == 'R') bonus = 1250; else bonus = 1000; else bonus = 0;
1000
What will be the value of ans after the following code has been executed? int ans = 10; int x = 65; int y = 55; if (x <= y) ans = x + y;
120
What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;
15
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }
20
What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales > 500) bonus = 25; else bonus = 0;
25
Which of the following will format 12.78 to display as 12.8%?
System.out.printf("%.1f%%", 12.78);
What will be the values of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }
ans = 35, x = 15, y = 40
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
Which of the following expressions will determine whether x is less than or equal to y?
x <= y