Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 5.12, Problem 5.12.3CP
Rewrite the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In c++ , perform deletion at the start, middle and end as well and perform the shrinking operation as well.
( Drop code in words , explain the code and drop the screenshot of output as well )
language is c++
sample output included with user input in bold
•Write a C++ program (practice4.2.1.CheckNumbers.cpp) that lets the user enter a series of integers, one at a time using a loop.
•The program will check and display if the input number is even or odd, and then calculate the sum of all input numbers. If the input number is zero (0), print out the sum of all inputted numbers, and then end the entire program.
Analyze the problem:
•Part-1: should use a for loop, while loop, or do-while loop to solve the problem?
ANS: Since starting point of the program will always be to ask user to enter an integer number, and then check that number. So use a do-while loop in the program is more appropriate for user inputs.
•Part-2 (bonus-part): use a while loop inside the do-while loop to do input validation.
•Part-3: If user entered zero (0), exit the do-while loop, but not exit the entire program, still need to print out the sum. So use break;statement
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
Can a class contain both instance variables and static methods?
Java: An Introduction to Problem Solving and Programming (8th Edition)
Java programmers concentrate on creating, which contain fields and the set of methods that manipulate those fie...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Which category of C++ reference variables always produces aliases?
Concepts Of Programming Languages
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
If the clamping force on the boards is 600 lb, determine the required magnitude of the couple force that must b...
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Describe two properties that each candidate key must satisfy.
Modern Database Management
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 in c++ ....arrow_forwardwrite a c++ code using stack,linked list. In quiz game, questions are chosen in such a a way that they cover all fields of a typical quiz contest. The user’s general knowledge is tested with quiz questions regarding science, technology, movies, sports, general health, geography and many more. Quiz Game Project Introduction: Functions of projects and below is some function used in project:- Edit score--adds the prize won to the previous one upon giving the right answer to a question Help-- menu with game summary and rules Show record--shows the highest cash prize won by a particular user Show score--to view the highest score Reset score--to reset the highest score/ default In quiz game project, we can store the user’s name, view the highest score secured by a user, and even reset the score. The game ends when the user’s cash prize piles up to 1000 RS. For each question there are 4 options A, B, C and D and no negative markings. so, money would not be…arrow_forwardFor this project, you will import the **time** and **random** modules. You will also install the **matplotlib** package and import from it the **pyplot** module. You will also import the wraps() function from the functools module for use in your decorator.Use the **time** module to write a decorator function named sort_timer that times how many seconds it takes the decorated function to run. Since sort functions don't need to return anything, have the decorator's wrapper function return that elapsed time.To get the current time, call time.perf_counter(). Subtracting the begin time from the end time will give you the elapsed time in seconds.Copy the code for bubble sort and insertion sort from Module 4 and decorate them with sort_timer. def bubble_sort(a_list): """ Sorts a_list in ascending order """ for pass_num in range(len(a_list) - 1): for index in range(len(a_list) - 1 - pass_num): if a_list[index] > a_list[index + 1]:…arrow_forward
- Write a C Program that allows a user to enter any number of student test scores until the user enters 999. If the score entered is less than 0 or more than 100, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average. Save the Project as TestScoreStatistics.cpp *Use loops and functions *Separate the implementation file from the definition file.arrow_forwardWrite in C++arrow_forwardWrite a C++ PROGRAM INCLUDE THE BSTREE.h, MAIN CPP, AND BSTREE.CPP and the text file and show the screenshot of the output. Please Don't use AVLTree. There is a real program developed by a computer company that reads a report ( running text ) and issues warnings on style and partially corrects bad style. You are to write a simplified version of this program with the following features: Statistics A statistical summary with the following information: Total number of words in the report Number of unique words Number of unique words of more than three letters Average word length Average sentence length An index (alphabetical listing) of all the unique words (see next page for a specific format) Style Warnings Issue a warning in the following cases: Word used too often: list each unique word of more than three letters if its usage is more than 5% of the total number of words of more than three letters Sentence length : write a warning message if the average sentence length is…arrow_forward
- Can you give me two ways to do itarrow_forwardWrite a C++ Program using classes, functions (recursive and otherwise), arrays and other C++ commands where a user enters the name of a file and the program calculates the amount of vowels (a e.iou -lower case and A ELO,U - UPPER CASE, separately!), the letters y, Y, ñ, Ѹ and punctuation marks in the file. You can use the Loren Ipsum generator online for a test file: https://es.lipsum.com/arrow_forwardImplement using python progeam 1) The Variables used here are as followes B : True if there is a Baseball Game on TV, False if not G: True if George watches TV, False if not C: True if George is out of Cat Food, False if not F: True if George feeds his cat, False if not. Let us say you are given some Training Data which represents what happens over a period of time (For example: This file contains what happens every evening over one specific year). Your Task is to learn the conditonal probabilty tables for the bayesian network from the training data. The training data will be formatted as follows: The first number is 0 if there is no baseball game on TV (B is false), and 1 if there is a baseball game on TV (B is true). The second number is 0 if George does not watch TV (G is false), and 1 if George watches TV (G is true). The third number is 0 if George is not out of cat food (C is false), and 1 if George is out of cat food (C is true). The fourth number is 0 if George does not feed…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Control Structures - while loop - do-while loop - for loop - Goto - break - continue statements; Author: EzEd Channel;https://www.youtube.com/watch?v=21l11_9Osd0;License: Standard YouTube License, CC-BY