Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 4, Problem 14SA
Explanation of Solution
Sentinel:
The special value, which signals that there are no more items from the list of items to be processed, is called as sentinel.
- Sentinel is used to hold special values to indicate that the user cannot enter additional values.
- It means when the user, the program, enters a sentinel value or loop control will be terminated.
- It is a value to indicate the user that the last grade of values has been entered.
- Sentinel value is used as a condition of termination in a recursive
algorithm or loop...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Why should you be careful when choosing a sentinel value?
(-465)10 + (325)10 = ?
Chirality
def is_left_handed(pips):
Even though this has no effect on fairness, pips from one to six are not painted on dice just any which way, but so that pips on the opposite faces always add up to seven. (This convention makes it easier to tell when someone tries to use crooked dice with certain undesirable pip values replaced with values that are more desirable for the cheater.) In each of the 23 = 8 corners of the cube, exactly one value from each pair of forbidden opposites 1-6, 2-5 and 3-4 meets two values chosen from the other two pairs of opposites. You can twist and turn any corner of the die to face you, and yet two opposite sides never spread into simultaneous view.
This discipline still allows for two distinct ways to paint the pips. If the numbers in the corner shared by the faces 1, 2, and 3 read out clockwise as 1-2-3, that die is left-handed, whereas if they read out as 1-3-2, that die is right-handed. Analogous to a pair of shoes made separately for the left and…
Chapter 4 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 4.1 - What will the following program segments display?...Ch. 4.2 - How many times will Hello World be printed in the...Ch. 4.2 - How many times will I love Java programming! be...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.5 - Name the three expressions that appear inside the...Ch. 4.5 - You want to write a for loop that displays I love...Ch. 4.5 - What will the following program segments display?...Ch. 4.5 - Write a for loop that displays your name 10 times.
Ch. 4.5 - Write a for loop that displays all of the odd...Ch. 4.5 - Write a for loop that displays every fifth number,...Ch. 4.6 - Write a for loop that repeats seven times, asking...Ch. 4.6 - In the following program segment, which variable...Ch. 4.6 - Prob. 4.15CPCh. 4.10 - What is the difference between an input file and...Ch. 4.10 - What import statement will you need in a program...Ch. 4.10 - What class do you use to write data to a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - What classes do you use to read data from a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - You are opening an existing file for output. How...Ch. 4.10 - What clause must you write in the header of a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is a double variable, and rand references...Ch. 4 - Prob. 1MCCh. 4 - Prob. 2MCCh. 4 - Prob. 3MCCh. 4 - What is each repetition of a loop known as? a....Ch. 4 - This is a variable that controls the number of...Ch. 4 - The while loop is this type of loop. a. pretest b....Ch. 4 - The do-while loop is this type of loop. a. pretest...Ch. 4 - The for loop is this type of loop. a. pretest b....Ch. 4 - This type of loop has no way of ending and repeats...Ch. 4 - This type of loop always executes at least once....Ch. 4 - This expression is executed by the for loop only...Ch. 4 - Prob. 12MCCh. 4 - This is a special value that signals when there...Ch. 4 - To open a file for writing, you use the following...Ch. 4 - To open a file for reading, you use the following...Ch. 4 - Prob. 16MCCh. 4 - This class allows you to use the print and println...Ch. 4 - This class allows you to read a line from a file....Ch. 4 - True or False: The while loop is a pretest loop.Ch. 4 - True or False: The do-while loop is a pretest...Ch. 4 - True or False: The for loop is a posttest loop.Ch. 4 - True or False: It is not necessary to initialize...Ch. 4 - True or False: One limitation of the for loop is...Ch. 4 - True or False: A variable may be defined in the...Ch. 4 - True or False: In a nested loop, the inner loop...Ch. 4 - True or False: To calculate the total number of...Ch. 4 - // This code contains ERRORS! // It adds two...Ch. 4 - Prob. 2FTECh. 4 - // This code contains ERRORS! int choice, num1,...Ch. 4 - Prob. 4FTECh. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a do-whi1e loop that asks the user to enter...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a for loop that calculates the total of the...Ch. 4 - Write a nested loop that displays 10 rows of #...Ch. 4 - Convert the while loop in the following code to a...Ch. 4 - Convert the do-while loop in the following code to...Ch. 4 - Convert the following while loop to a for loop:...Ch. 4 - Convert the following for loop to a while loop:...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write nested loops to draw this pattern:Ch. 4 - Write nested loops to draw this pattern: ## # # #...Ch. 4 - Complete the following program so it displays a...Ch. 4 - Complete the following program so it performs the...Ch. 4 - Prob. 17AWCh. 4 - Prob. 18AWCh. 4 - Modify the code you wrote in Question 18 so it...Ch. 4 - Write code that opens a file named NumberList.txt...Ch. 4 - Prob. 1SACh. 4 - Why should you indent the statements in the body...Ch. 4 - Describe the difference between pretest loops and...Ch. 4 - Why are the statements in the body of a loop...Ch. 4 - Describe the difference between the while loop and...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use when you know the number...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Prob. 11SACh. 4 - What does it mean to let the user control a loop?Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 14SACh. 4 - Describe a programming problem requiring the use...Ch. 4 - How does a file buffer increase a programs...Ch. 4 - Why should a program close a file when its...Ch. 4 - What is a files read position? Where is the read...Ch. 4 - When writing data to a file, what is the...Ch. 4 - What does the Scanner classs hasNext method return...Ch. 4 - What is a potential error that can occur when a...Ch. 4 - Prob. 22SACh. 4 - How do you open a file so that new data will be...Ch. 4 - Sum of Numbers Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Distance File Modify the program you wrote for...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Prob. 5PCCh. 4 - File Letter Counter Write a program that asks the...Ch. 4 - Hotel Occupancy A hotels occupancy rate is...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Population Write a program that will predict the...Ch. 4 - Largest and Smallest Write a program with a loop...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Bar Chart Write a program that asks the user to...Ch. 4 - File Head Display Write a program that asks the...Ch. 4 - Line Numbers Write a program that asks the user...Ch. 4 - Uppercase File Converter Write a program that asks...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Random Number Guessing Game Write a program that...Ch. 4 - Random Number Guessing Game Enhancement Enhance...Ch. 4 - ESP Game Write a program that tests your ESP...Ch. 4 - Square Display Write a program that asks the user...Ch. 4 - Dice Game Write a program that plays a simple dice...Ch. 4 - Prob. 22PCCh. 4 - Personal Web Page Generator Write a program that...
Knowledge Booster
Similar questions
- ASSIGNMENT BRIEF Introduction Roulette is a popular casino game named after the French word for 'little wheel'. In the game, players may choose to place bets on single numbers or various groupings which will determine their payout. To determine the winning number a ball is spun in the opposite direction of a spinning wheel. As the ball loses momentum it comes to rest in one of the slots of the wheel. Winnings are then paid to anyone who places a successful bet. n 00 2. 1ST12 2ND12 3RD12 1T018 EVEN ODD |19то36 Figure 1: Layout of a European roulette table Numbers can be classified in several ways: 1. Red or Black 2. Odd or Even 3. High or Low - if a number is in the first half of the table it is considered low (1-18). If a number is in the second half of the table, it is considered high (19-36). 4. Dozens - a number can be in the first dozen(1-12), second dozen (13-24) or third dozen (25-36) 5. Columns - A number may be in any of the three columns of the table 6. Zero - the number '0'…arrow_forwardcheck_game_over(): as the name suggests, this function should check to see if the game is over (if one side has no stones left in all of its pockets). It takes as an argument the game board and should return True if the game is over and False otherwise.arrow_forward(Numerical) Write an assignment statement to calculate the nth term in an arithmetic sequence. This is the formula for calculating the value, v, of the nth term: v=a+(n1)d a is the first number in the sequence. d is the difference between any two numbers in the sequence.arrow_forward
- Discrete Mathematics: Assignment details: Replace all the 0 (Zero) digits in your ID by 4. Example: If your ID is 38104680, it becomes 38144684 Take the first 6 digits and substitute them in this expression (( A + B) / C) * ((D-E)/F)-2) according to the following table; Letter Replace by Digit Example Digit A 1st 3 B 2nd 8 C 3rd 1 D 4th 4 E 5th 4 F 6th 6 After substitution your expression will be similar to this (( 3 + 8) / 1) * ((4-4)/6)-2). Draw a rooted tree that represents your expression. What is the prefix form of this expression. 3.What is the value of the prefix expression obtained in step 2 above?arrow_forwarddesign patterns quetion public double calculatePerimeter(Shapes [] shapes) { double p = 0;for (Shape shape : shapes) { if (shape is Rectangle) { Rectangle rectangle = (Rectangle) shape; p += (rectangle.Width+rectangle.Height) * 2; } else { Circle circle = (Circle)shape; p += 2 * circle.Radius * Math.PI; } } return p; } which design principle is violated in the above code? what is the issue/ limitation of this code? rewrite the code to not violate the design principle you answered in part 1?arrow_forward# Segmentation Questionarrow_forward
- MPI Lab Directions Write an MPI program, countprimes which will count the number of prime numbers in the numbers from 1 to n inclusive where n is a long integer. The value for n which should be set in the program using a constant should be 50,000. Each process will test its share of the cases. Each process should not print out any primes that it finds, but it should keep a running total. Before the process finishes, it should print out its ID number and its count of primes that it found. The master process should end with printing a total for the count of the number of primes and the total amount of time taken to find all the primes. Take a screenshot of the output for running this with 5 processes. Before submission, make sure you clean up the directories so that no miscellaneous files are kept around in the submission. (Grade would be deducted if useless files are found in the homework directories.) Include the source code, screenshot, and the Makefile in the submission. Your…arrow_forwardJAVA based program need helparrow_forward11 Worksheet 5 Note:Solution using Matlab Code Write a program that prompts the user to enter a number within the range of 1 through 7, those numbers represent the weekdays as shown in the table. If the entered number is more than 7, display 'invalid day'. Number 1 2 3 4 5 6 7 Day Sunday Monday Tuesday Wednesday Thursday Friday Saturday Type of the day Workday Workday Workday Workday Workday Weekend Weekend The program should continue to repeat itself 10 times, after which, the program should stop. Furthermore, the program should be able to show a message saying if this is a 'workday' or a 'weekend day'. Note: you are required to add a comment beside your command. Hint: to add a comment you may use the % sign. thank guys you dodo great.arrow_forward
- "Type" doesn't specify a variable. Data types distinguish variables. How can this concept explain any variable?arrow_forwardPython Knapsack: you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a1, a2, ... , an} and associated weights W={w1, w2, ... , wn}. Here the weights and values are all positive. You wish to maximize the total value of the items you select not exceeding the given weight capacity, example, maximize sum_{a in A} such that sum_{w in W} <= C. Note that you can only select your items once. In Python, create function DP_K (C, A, W) as stated above. Input an array to the function to hold the backtrace. What is the best set of items for C = 30, A = [40, 110, 100] and w = [20, 30, 40]? This can be shown using auxiliary printing function.arrow_forwardA Hide Time Remaining A Geometric Progression Printer As you might recall, a Geometric Progression (or GP) is a sequence of elements in which the next number in the sequence is obtained by multiplying the previous number by the common ratio. The next number in the sequence is obtained by using this formula: a_n=a_1*r(n-1) While the sum of all numbers in the sequence is obtained using any of these formulae: If r= 1, sum=a*n Ifr != 1 and r> 1, sum = a[(rª-1)/(r - 1)] Ifr != 1 and r < 1, sum = a[(1-r)/(1-r)] where a_n = next number in the sequence, a_1 = first number in the sequence, r = common ratio, n = number of terms Your task is to write a Python program that 1: Accepts the necessary inputs from the user, i.e., start value (a_1), common ratio (r), and number of generate to generate (n). 2. Generates the Geometric Progression (GP) sequence starting from a_1 to n. 3. Prints out the GP HORIZONTALLY not VERTICALLY, e.g. 3, 9, 27, 81, 243, 729.... 4. Calculates the sum of all numbers in…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 Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr