Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Fill in the blanks in each of the following statements: a) Typically, ________ statements are used for counter-controlled repetition and _________ statements are used for sentinel-controlled repetition. b) The do…while statement tests the loop-continuation condition __________ executing the loop’s body; therefore, the body always executes at least once. c) The __________ statement selects among multiple actions based on the possible values of an integer variable or expression. d) The __________ statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. e) The __________ operator can be used to ensure that two conditions are both true before choosing a certain path of execution. f) If the loop-continuation condition in a for header is initially ___________ , the program does not execute the for statement’s body. g) Methods that perform common tasks and do not require objects are called _____________ methods.

Problem 2

State whether each of the following is true or false. If false, explain why. a) The default case is required in the switch selection statement. b) The break statement is required in the last case of a switch selection statement. c) The expression ( ( x > y ) && ( a < b ) ) is true if either x > y is true or a < b is true. d) An expression containing the || operator is true if either or both of its operands are true. e) The comma (,) formatting flag in a format specifier (e.g., %,20.2f) indicates that a value should be output with a thousands separator. f) To test for a range of values in a switch statement, use a hyphen (–) between the start and end values of the range in a case label. g) Listing cases consecutively with no statements between them enables the cases to perform the same set of statements.

Problem 5

Describe the four basic elements of counter-controlled repetition.

Problem 6

Compare and contrast the while and for repetition statements.

Problem 7

Discuss a situation in which it would be more appropriate to use a do....while statement than a while statement. Explain why.

Problem 8

Compare and contrast the break and continue statements.

Problem 9

Find and correct the error(s) in each of the following segments of code: a) for ( i = 100, i >= 1, i++ ) System.out.println( i ); b) The following code should print whether integer value is odd or even: switch ( value % 2 ) { case 0: System.out.println( "Even integer" ); case 1: System.out.println( "Odd integer" ); } c) The following code should output the odd integers from 19 to 1: for ( i = 19; i >= 1; i += 2 ) System.out.println( i ); d) The following code should output the even integers from 2 to 100: counter = 2; do { System.out.println( counter ); counter += 2; } While ( counter < 100 );

Problem 11

Write an application that finds the smallest of several integers. Assume that the first value read specifies the number of values to input from the user.

Problem 12

Write an application that calculates the product of the odd integers from 1 to 15.

Problem 13

Factorials are used frequently in probability problems. The factorial of a positive integer \(n\) (written \(n !\) and pronounced " \(n\) factorial") is equal to the product of the positive integers from 1 to \(n .\) Write an application that evaluates the factorials of the integers from 1 to \(5 .\) Display the results in tabular format. What difficulty might prevent you from calculating the factorial of 20 ?

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks