Chapter 5: Problem 6
Compare and contrast the while and for repetition statements.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
Chapter 5: Problem 6
Compare and contrast the while and for repetition statements.
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for free
Fill in the blanks in each of the following statements: a) Typically, ______________ statements are used for counter-controlled repetition and __________ statements 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, or a String. 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.
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 calculates the factorials of 1 through \(20 .\) Use type long. Display the results in tabular format. What difficulty might prevent you from calculating the factorial of \(100 ?\)
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.
Describe the four basic elements of counter-controlled repetition.
In this chapter, we discussed the logical operators \(\& \&, \&,||, |, \wedge\) and \(!\) De Morgan's laws can sometimes make it more convenient for us to express a logical expression. These laws state that the expression ! ( condition 1 \&\& condition2) is logically equivalent to the expression \((! \text { condition } 1 \text { I } | \text { ! condition } 2 \text { ). Also, the expression } ! \text { (condition1 }\) | | condition2) is logically equivalent to the expression ( 1 condition 1 88 ! condition2). Use De Morgan's laws to write equivalent expressions for each of the following, then write an application to show that both the original expression and the new expression in each case produce the same value: a) !(x < 5) && !(y >= 7) b) !(a == b) || !(g != 5) c) !((x <= 8) && (y > 4)) d) !((i > 4) || (j <= 6))
What do you think about this solution?
We value your feedback to improve our textbook solutions.