Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 5.12, Problem 5.12.4CP
After the break statement in (a) is executed in the following loop, which statement is executed? Show the output. After the continue statement in (b) is executed in the following loop, which statement is executed? Show the output.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Indicate whether the statement is true or false.
1. Ifthe initial condition of any while loop is false it will still execute once.
2. In the case of an infinite while loop, the while expression (that is, the loop condition) is always true.
3. A counter-controlled loop is used when the exact number of data entries is known.
4. The control variable in a flag-controlled while loop is an int variable.
5. A break statement is legal in a while loop, but not in a for loop.
6. Void methods have no return data type.
7. Ifa formal parameter is a variable of a primitive data type, then after copying the value of the actual
parameter, there is no connection between the formal and actual parameter.
8. All the methods defined in a class must háve different names.
9. The statement
int () list = new int[15);
creates list to be an array of 14 components because array index starts at 0.
10. When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.
11. Members of a class are usually classified into…
Which of the following apply to the while loop only? To the do...while loop only? To both? a. It is considered a conditional loop.b. The body of the loop executes at least once.c. The logical expression controlling the loop is evaluated before the loop is entered.d. The body of the loop may not execute at all.
Chapter 5 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 5.2 - Prob. 5.2.1CPCh. 5.2 - How many times are the following loop bodies...Ch. 5.2 - Prob. 5.2.3CPCh. 5.3 - What is wrong if guess is initialized to 0 in line...Ch. 5.4 - Revise the code using the System. nanoTime () to...Ch. 5.5 - Prob. 5.5.1CPCh. 5.6 - Prob. 5.6.1CPCh. 5.6 - What are the differences between a while loop and...Ch. 5.7 - Do the following two loops result in the same...Ch. 5.7 - What are the three parts of a for loop control?...
Ch. 5.7 - Suppose the input is 2 3 4 5 0. What is the output...Ch. 5.7 - What does the following statement do? for ( ; ; )...Ch. 5.7 - If a variable is declared in a for loop control,...Ch. 5.7 - Convert the following for loop statement to a...Ch. 5.7 - Count the number of iterations in the following...Ch. 5.8 - Can you convert a for loop to a while loop? List...Ch. 5.8 - Can you always convert a while loop into a for...Ch. 5.8 - Identify and fix the errors in the following code:...Ch. 5.8 - Prob. 5.8.4CPCh. 5.9 - How many times is the println statement executed?...Ch. 5.9 - Show the output of the following programs. (Hint:...Ch. 5.11 - Will the program work if n1 and n2 are replaced by...Ch. 5.11 - In Listing 5.11. why is it wrong if you change the...Ch. 5.11 - In Listing 5. 11, how many times the loop body is...Ch. 5.11 - Prob. 5.11.4CPCh. 5.11 - Prob. 5.11.5CPCh. 5.12 - What is the keyword break for? What is the keyword...Ch. 5.12 - The for loop on the left is converted into the...Ch. 5.12 - Rewrite the programs TestBreak and TestContinue in...Ch. 5.12 - After the break statement in (a) is executed in...Ch. 5.13 - What happens to the program if (low high) in line...Ch. 5.14 - Simply the code in lined 27-32 using a conditional...Ch. 5 - (Count positive and negative numbers and compute...Ch. 5 - (Repeat additions) Listing 5.4,...Ch. 5 - (Conversion from kilograms to pounds) Write a...Ch. 5 - (Conversion from miles to kilometers) Write a...Ch. 5 - (Conversion from kilograms to pounds and pounds to...Ch. 5 - Prob. 5.6PECh. 5 - (Financial application: compute future tuition)...Ch. 5 - (Find the highest score) Write a program that...Ch. 5 - (Find the two highest scores) Write a program that...Ch. 5 - (Find numbers divisible by 5 and 6) Write a...Ch. 5 - (Find numbers divisible by 5 or 6, but not both)...Ch. 5 - (Find the smallest n such that n2 12,000) Use a...Ch. 5 - (Find the largest n such that n3 12,000) Use a...Ch. 5 - (Compute the greatest common divisor) Another...Ch. 5 - (Display the ASCII character table) Write a...Ch. 5 - (Find the factors of an integer) Write a program...Ch. 5 - (Display pyramid) Write a program that prompts the...Ch. 5 - (Display four patterns using Loops) Use nested...Ch. 5 - (Display numbers in a pyramid pattern) Write a...Ch. 5 - (Display prime numbers between 2 and 1,000) Modify...Ch. 5 - Prob. 5.21PECh. 5 - For the formula to compute monthly payment, see...Ch. 5 - (Demonstrate cancellation errors) A cancellation...Ch. 5 - Prob. 5.24PECh. 5 - (Compute ) You can approximate by using the...Ch. 5 - (Compute e) You can approximate e using the...Ch. 5 - (Display leap years) Write a program that displays...Ch. 5 - (Display the first days of each month) Write a...Ch. 5 - (Display calendars) Write a program that prompts...Ch. 5 - (Financial application: compound value) Suppose...Ch. 5 - (Financial application: compute CD value) Suppose...Ch. 5 - (Game: lottery) Revise Listing 3.8, Lottery.java,...Ch. 5 - (Perfect number) A positive integer is called a...Ch. 5 - (Game: scissor; rock, paper) Programming Exercise...Ch. 5 - (Summation) Write a program to compute the...Ch. 5 - (Business application: checking ISBN) Use loops to...Ch. 5 - (Decimal to binary) Write a program that prompts...Ch. 5 - (Decimal to octal) Write a program that prompts...Ch. 5 - (Financial application: find the sales amount) You...Ch. 5 - (Simulation: heads or tails) Write a program that...Ch. 5 - (Occurrence of max numbers) Write a program that...Ch. 5 - (Financial application: find the sales amount)...Ch. 5 - (Math: combinations) Write a program that displays...Ch. 5 - (Computer architecture: bit-level operations) A...Ch. 5 - (Statistics: compute mean and standard deviation)...Ch. 5 - (Reverse a string) Write a program that prompts...Ch. 5 - (Business: check ISBN-13) ISBN -13 is a new...Ch. 5 - (Process string) Write a program that prompts the...Ch. 5 - (Count vowels and consonants) Assume that the...Ch. 5 - Prob. 5.50PECh. 5 - (Longest common prefix) Write a program that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Population Data If you have downloaded this books source code (the companion Web site is available at www.pears...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Under what circumstances would a subclass need to override a superclass method?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
What is the period if the clock frequency is 3.5 GHz? Figure 1-62
Digital Fundamentals (11th Edition)
The following code contains several nested if-else statements. Unfortunately, it was written without proper ali...
Starting Out with Python (3rd Edition)
Write a version of the inner product procedure described in Problem 5.13 that uses 6 1 loop unrolling. For x86...
Computer Systems: A Programmer's Perspective (3rd Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a program segment with a do-while loop that displays whether a user- entered integer is even or odd. The code should then ask the user if he or she wants to test another number. The loop should repeat so long as the user enters Y or y. Use a logical OR operator in the do-while loop test expression.arrow_forwardPlease don't copy the answer but fast solve the issuearrow_forwardWhich of the following statements is true exclusively for the while loop? Only to the do...while loop? To both of you? It's a conditional loop, for starters. The loop's body is executed at least once. Before the loop is entered, the logical expression controlling the loop is evaluated. The loop's body may or may not execute.arrow_forward
- Write the code to display the following pattern using two pretest loops along with the letter X. Use the Do...Loop statement for the outer loop. Use the For...Next statement for the nested loop. Display the pattern in the lblPattern control.XXXXXXXXXXXXarrow_forwardWhich of the following statements is false? Select one: O It is possible that the body of a while loop may not execute at all. O do.while may not execute at all, but for loop always executes at least once O Executing a break statement in the body of a loop immediately terminates the loop O If you know or can determine in advance the number of repetitions needed, the Counter-controlled while loop is a right choicearrow_forwardWhich of the following statements is true? OThe boolean test that make up the loop test is found in the body of the loop The key word while indicates the type of loop (pre-test) The loop body is indented at the same level as the key word while OThe boolean expression is followed immediately by the keyword endarrow_forward
- Basic while loop expression. Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example output for userNum = 160:40 10 2 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forwardHomework 1- Write a for statement to count from 100 to 200 by twos. 3. Write a while loop to count from 100 to 200 by twos. 1- 4. Write a do...while loop to count from 100 to 200 by twos. AParrow_forwardQ7arrow_forward
- The condition in a posttest loop can be phrased as either a looping condition or a loop exit condition.a. Trueb. Falsearrow_forwardSample output This is from one continuous run of the program. Please enter a product name. You can also enter x to quit: laptop Please enter the product's category: tech Please enter the product's price: 100 The new SKU is LAP and the new price is 110.00000000000001 Please enter a product name. You can also enter x to quit: scantron Please enter the product's category: office Please enter the product's price: .75 The new SKU is RON and the new price is 0.8250000000000001 Please enter a product name. You can also enter x to quit: whiteboard cleaner Please enter the product's category: other Please enter the product's price: 8 The new SKU is WHITEBOARD CLEANER and the new price is 8.8 Please enter a product name. You can also enter x to quit: xarrow_forwardWrite a postcondition, event-controlled loop (i.e., a while loop), using a break statement, that prints the numbers 8, 14, 20, 26, 32, and 38 to the terminal (one per line).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License