AAHW 7

docx

School

Black Hills State University *

*We aren’t endorsed by this school

Course

494

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

20

Uploaded by DrKnowledgeTurkey33

Report
HW 7 TRUE/FALSE 1. Programs never need more than one path of execution. FALSE 2. The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false . TRUE 4. All it takes for an OR expression to be true is for one of the subexpressions to be true . TRUE
5. All it takes for an AND expression to be true is for one of the subexpressions to be true . FALSE 8. If the expression on the left side of the && operator is false , the expression on the right side will not be checked. FALSE 10. A local variable's scope always ends at the closing brace of the block of code in which it is declared. TRUE 14. The System.out.printf method formats a string and displays it in the console window.
TRUE 15. When you write a switch statement using arrow case syntax, you must have a break statement in each case section. TRUE MULTIPLE CHOICE 1. In an if-else statement, if the boolean expression is false then a. no statements or blocks are executed b. the statement or block following the else is executed c. the first statement or block is executed d. all the statements or blocks are executed
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
3. __________ operators are used to determine whether a specific relationship exists between two values. a. Assignment c. Logical b. Arithmetic d. Relational 4. If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal? a. str1 = str2 c. str1.equals(str2) b. str1 && str2 d. str1 += str2 6. A block of code is enclosed in a set of a. braces, { } c. brackets, [ ] b. parentheses, ( ) d. double quotes, " "
7. The boolean expression in an if statement must evaluate to a. degrees or radians c. positive or negative b. true or false d. left or right 8. A flag may have the values a. defined or undefined c. of any range of integers b. true or false d. of any Unicode character 9. 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; }
a. ans = 60 , x = 0 , y = 50 b. ans = 45 , x = 50 , y = 0 c. ans = 45 , x = 50 , y = 50 d. ans = 60 , x = 50 , y = 100 10. 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; a. 60 b. 75 c. 15 d. 135 11. What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
(sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250; a. 750 b. 1250 c. 500 d. 1000 12. 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; a. 0.0 b. 0.05 c. 0.03 d. 0.01
13. What will 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 = 0.05; else discountRate = 0.04; else if (purchase > 750) if (cust == 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0; a. 0.0 b. 0.04 c. 0.05 d. 0.03
16. 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; a. 30 c. 50 80 d. The code contains an error and will not compile. 17. What will be displayed after the following statements are executed? int ans = 10; int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans); a. 10 c. 100 b. 120 d. The code contains an error and will not compile.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
18. What will be displayed after the following statements are executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); } a. 40 c. 20 b. 30 d. The code contains an error and will not compile. 19. What will be the value of pay after the following statements are executed? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) *payRate * 1.5; a. 400.00 c. 465.00 b. 450.00 d. 475.00
20. Which of the following expressions determines whether the char variable, chrA , is not equal to the letter 'A' ? a. chrA == 'A' c. chrA || 'A' b. chrA != 'A' d. chrA.notEquals(A) 21. A __________ is a boolean variable that signals when some condition exists in the program. a. sentinel c. block b. flag d. case 22. The __________ statement is used to create a decision structure which allows a program to have more than one path of execution. a. block c. null
b. if d. flag 24. Java requires that the boolean expression being tested by an if statement be enclosed in a. a set of parentheses c. a set of double quotes b. a set of braces d. a set of brackets 25. Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)? a. if (temp >= 0 && temp <= 100) b. if (temp > 0 && temp < 100) c. if (temp >= 0 || temp <= 100) d. if (temp > 0 || temp < 100)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
26. Which of the following expressions will determine whether x is less than or equal to y ? a. x <= y c. x >= y b. x => y d. x =< y 27. Which of the following is the not equal operator? a. <> b. NOT c. *& d. != 29. 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;
a. 100 b. 500 c. 25 d. 0 33. ________ works like this: If the expression on the left side of the && operator is false , the expression the right side will not be checked. a. short-circuit evaluation c. Boolean logic b. reverse logic d. relational evaluation 36. An expression tested by an if statement must evaluate to a. 0 or 1 c . true or false b. +1 or -1 d. t or f
TRUE/FALSE 4. In a for loop, the control variable is always incremented. TRUE 5. The do-while loop must be terminated with a semicolon. TRUE 6. The do-while loop is ideal in situations where you always want the loop to iterate at least once.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
TRUE 9. The while loop is always the best choice in situations where the exact number of iterations is known. FALSE 10. Java provides a set of simple unary operators designed just for incrementing and decrementing variables. TRUE 11. The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true . TRUE 12. In a for loop, the control variable cannot be initialized to a constant value and tested against a constant value. FALSE
MULTIPLE CHOICE 1. A loop that repeats a specific number of times is known as a(n) __________ loop. a. count-controlled c. conditional b. infinite d. pretest 2. A __________ loop will always be executed at least once. a. pretest c. conditional b. posttest d. user-controlled 4. Before entering a loop to compute a running total, the program should first a. set the accumulator variable to an initial value, often zero b. set all variables to zero
c. read all the values into main memory d. know exactly how many values there are to total 6. A loop that executes as long as a particular condition exists is called a(n) __________ loop. a. infinite c. conditional b. count-controlled d. relational 8. The variable used to keep a running total in a loop is called a(n) __________. a. accumulator c. summation b. sentinel d. integer 9. This type of loop has no way of ending and repeats until the program is interrupted . a. indeterminate b. interminable c. infinite
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
d. timeless 10. This type of loop always executes at least once. a. while b. do-while c. for d. any of these 11. This expression is executed by the for loop only once, regardless of the number of iterations. a. initialization expression b. test expression c. update expression d. pre-increment expression 12. This is a variable that keeps a running total. a. sentinel b. sum c. total d. accumulator 13. This is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a. sentinel
b. flag c. signal d. accumulator