Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 4.2, Problem 10SC
Explanation of Solution
Given pseudocode:
//set the "count" value as "1"
count = 1
//set the "temp" value as "n"
temp = n
//check whether the "temp" value is less than "10" or not
while( temp > 10)
//increment the "count" value
increment count
//divide the "temp" by "10"
Divide temp by 10.0
Hand-tracing the above code:
- In the above code, there are two variables “count” and “temp”.
- First “count” is initialized as “1”.
- Value of “temp” is “123”, since value of “n” is 123.
- If the value of “temp” is greater than “10”, then “while” loop executes and the value of “count” is incremented to 1 now the “count” value is 2.
- Then value of “temp” is divided by 10, now the new “temp” value is “12...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a pseudocode that calculates the least common multiple between a number (a) and a number (b).
What is the step count of the pseudocode below:
for i=0 to 8 do
for j = 0 to n do
s = s+ i * j
endfor
endfor
What is the step count of the pseudocode below:
k=0
for i=0 to 10 do
for j = 1 to i do
k++
endfor
endfor
Chapter 4 Solutions
Big Java Late Objects
Ch. 4.1 - How many years does it take for the investment to...Ch. 4.1 - If the interest rate is 10 percent per year, how...Ch. 4.1 - Modify the program so that the balance after each...Ch. 4.1 - Suppose we change the program so that the...Ch. 4.1 - What does the following loop print? int n = 1;...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, assuming that a is...Ch. 4.2 - Trace the following code. What error do you...Ch. 4.2 - Prob. 10SC
Ch. 4.3 - Write the for loop of the InvestmentTable.java...Ch. 4.3 - How many numbers does this loop print? for (int n...Ch. 4.3 - Write a for loop that prints all even numbers...Ch. 4.3 - Write a for loop that computes the sum of the...Ch. 4.3 - How would you modify the for loop of the...Ch. 4.4 - Prob. 16SCCh. 4.4 - Rewrite the input check do loop using a while loop...Ch. 4.4 - Suppose Java didnt have a do loop. Could you...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.5 - What does the SentinelDemo.java program print when...Ch. 4.5 - Why does the SentinelDemo.java program have to...Ch. 4.5 - What would happen if the declaration of the salary...Ch. 4.5 - In the last example of this section, we prompt the...Ch. 4.5 - Prob. 25SCCh. 4.6 - Prob. 26SCCh. 4.6 - Google has a simple interface for converting...Ch. 4.6 - Consider a modification of the program in Self...Ch. 4.6 - Prob. 29SCCh. 4.6 - Produce a storyboard for a program that compares...Ch. 4.7 - What total is computed when no user input is...Ch. 4.7 - Prob. 32SCCh. 4.7 - What are the values of position and ch when no...Ch. 4.7 - Prob. 34SCCh. 4.7 - Prob. 35SCCh. 4.7 - Prob. 36SCCh. 4.8 - Why is there a statement System.out.println(); in...Ch. 4.8 - How would you change the program to display all...Ch. 4.8 - Prob. 39SCCh. 4.8 - What do the following nested loops display? for...Ch. 4.8 - Prob. 41SCCh. 4.9 - Prob. 42SCCh. 4.9 - You need to write a program for DNA analysis that...Ch. 4.9 - Prob. 44SCCh. 4.9 - Consider the task of finding numbers in a string....Ch. 4.10 - How do you simulate a coin toss with the...Ch. 4.10 - How do you simulate the picking of a random...Ch. 4.10 - Why does the loop body in Dice.java call...Ch. 4.10 - Prob. 49SCCh. 4.10 - Prob. 50SCCh. 4 - Given the variables String stars = ""; String...Ch. 4 - What do these loops print? a. int i = 0; int j =...Ch. 4 - What do these code snippets print? a. int result =...Ch. 4 - Write awhile loop that prints a. All squares less...Ch. 4 - Write a loop that computes a. The sum of all even...Ch. 4 - Provide trace tables for these loops. a. int i =...Ch. 4 - What do these loops print? a. for (int i = 1; i ...Ch. 4 - What is an infinite loop? On your computer, how...Ch. 4 - Write a program trace for the pseudocode in...Ch. 4 - What is an off-by-one error? Give an example from...Ch. 4 - What is a sentinel value? Give a simple rule when...Ch. 4 - Which loop statements does Java support? Give...Ch. 4 - How many iterations do the following loops carry...Ch. 4 - Write pseudocode for a program that prints a...Ch. 4 - Prob. 15RECh. 4 - Write pseudocode for a program that reads a...Ch. 4 - Write pseudocode for a program that reads a...Ch. 4 - Rewrite the following for loop into a while loop....Ch. 4 - Rewrite the following do loop into a while loop....Ch. 4 - Provide trace tables of the following loops. a....Ch. 4 - What do the following loops print? Work out the...Ch. 4 - What do the following program segments print? Find...Ch. 4 - Prob. 23RECh. 4 - Add a storyboard panel for the conversion program...Ch. 4 - In Section 4.6, we decided to show users a list of...Ch. 4 - Change the storyboards in Section 4.6 to support a...Ch. 4 - Draw a flowchart for a program that carries out...Ch. 4 - In Section 4.7.5, the code for finding the largest...Ch. 4 - What are nested loops? Give an example where a...Ch. 4 - The nested loops for (int 1 = 1; 1 = height; i++)...Ch. 4 - Suppose you design an educational game to teach...Ch. 4 - In a travel simulation, Harry will visit one of...Ch. 4 - Write programs with loops that compute a. The sum...Ch. 4 - Write programs that read a sequence of integer...Ch. 4 - Write programs that read a line of input as a...Ch. 4 - Complete the program in How To 4.1 on page 171....Ch. 4 - Write a program that reads a set of floating-point...Ch. 4 - Translate the following pseudocode for finding the...Ch. 4 - Translate the following pseudocode for randomly...Ch. 4 - Write a program that reads a word and prints each...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints all...Ch. 4 - Write a program that reads a string and prints the...Ch. 4 - Write a program that reads a sequence of words and...Ch. 4 - Write a program that prints all powers of 2 from...Ch. 4 - Write a program that reads a number and prints all...Ch. 4 - Prob. 18PECh. 4 - Write a program that reads an integer and...Ch. 4 - Write a program that reads an integer and...Ch. 4 - Write a program to plot the following face.Ch. 4 - Write a graphical application that displays a...Ch. 4 - Enhance Worked Example 4.1 to check that the...Ch. 4 - Mean and standard deviation. Write a program that...Ch. 4 - The Fibonacci numbers are defined by the sequence...Ch. 4 - Factoring of integers. Write a program that asks...Ch. 4 - Prime numbers. Write a program that prompts the...Ch. 4 - The game of Nim. This is a well-known game with a...Ch. 4 - The Drunkards Walk. A drunkard in a grid of...Ch. 4 - The Monty Hall Paradox. Marilyn vos Savant...Ch. 4 - A simple random generator is obtained by the...Ch. 4 - The Buffon Needle Experiment. The following...Ch. 4 - In the 17th century, the discipline of probability...Ch. 4 - Write a program that reads an initial investment...Ch. 4 - Currency conversion. Write a program that first...Ch. 4 - Write a program that first asks the user to type...Ch. 4 - Your company has shares of stock it would like to...Ch. 4 - Write an application to pre-sell a limited number...Ch. 4 - You need to control the number of people who can...Ch. 4 - Credit Card Number Check. The last digit of a...Ch. 4 - In a predator-prey simulation, you compute the...Ch. 4 - Projectile flight. Suppose a cannonball is...Ch. 4 - Radioactive decay of radioactive materials can be...Ch. 4 - The photo at left shows an electric device called...Ch. 4 - Write a graphical application that draws a spiral,...Ch. 4 - Prob. 28PPCh. 4 - Draw a picture of the four-leaved rose whose...
Knowledge Booster
Similar questions
- A star triangle is a triangle using asterisks “*”. Write a java program that takes an integer N as input from the keyboard and output a star triangle of size N. Use nested for loops to solve this problem. See example 6.17 from the book to get an idea about how to solve this problem. Sample Input and output: Sample 1 Input: 5 Output: * ** *** **** ***** Sample 2 Input: 3 Output: * ** ***arrow_forwardWrite pseudocode that will calculate a running sum. A user will enter numbers that will be added to the sum and when a negative number is encountered, stop adding numbers and write out the final resultarrow_forwardPython Programming Python Programming.Write a program that reads a positive integer n, and prints the firstn even numbers. For example, one execution would look like this:Please enter a positive integer: 3246arrow_forward
- This needs to be done in Java Write an application that prints out the temperatures from 0 - 50 degrees Celsius and the converted the Fahrenheit values. Use a while counter controlled loop. Include column headings and correct column spacing. SAMPLE OUTPUT: Celsius Fahrenheit0 32.01 33.82 35.63 37.4arrow_forwardFor i) Please write in pseudocode For ii) Please give detail answer and complete explanation .arrow_forwardWrite a program using python that will do simple math calculations using the basic operations. Refer to the sample output below. Input 1. First Number 2. Second Number Output Output·Sample: Enter·first·number:·87 Enter·second·number:·9 The·sum·of·87·and·9·is·96.00 The·difference·of·87·and·9·is·78.00 The·product·of·87·and·9·is·783.00 The·quotient·of·87·and·9·is·9.67 The·remainder·of·87·and·9·is·6.00 The·square·root·of·87.000·is·9.33arrow_forward
- In Java, design a program that uses nested loops to display a multiplication table for numbers 1 through 12.arrow_forwardThe property of addition states that two numbers can be added in either order to get the same result.arrow_forwardRewrite the following pseudocode segment using a loop structure in KOTLIN k = (j +15) / 27loop:if k > 10 then goto out k=k+1i=3*k-2goto loopout: . . .arrow_forward
- An Armstrong number is a number of n digits that is equal to the sum of each digit raised to the nth power. For example, 153 (which has three digits) equals (1^3 )+ (5^3) +(3^3) . Find out all three digit Armstrong numbers and display those numbers on 7-segment LEDS for at least 2 seconds. *USE C PROGRAMING FOR MICROPROCESSOR*arrow_forwardMust be written in Python The amount of time a doctor spends with each patient is exponentially distributed with a mean of 8 minutes. Write a piece of code to compute the probability of them spending less than 5 minutes with their next patient. Your code should print out the probability, rounded to 4 decimal places.arrow_forwardWhat is the step count of the pseudocode below: if (i%2 == 0) then S = S + i*i else i++ S = S + i*i endifarrow_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 LearningProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning