Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4, Problem 5RE
Write a loop that computes
- a. The sum of all even numbers between 2 and 100 (inclusive).
- b. The sum of all squares between 1 and 100 (inclusive).
- c. The sum of all odd numbers between a and b (inclusive).
- d. The sum of all odd digits of n. (For example, if n is 32677, the sum would be 3 + 7 + 7 = 17.)
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question 2: Write a program to read student ID and check whether it is odd/even number. Output a 4X4 badge if the student ID is even number and output a 3X3 badge if it is odd number. The badge is built up by the (height X width) of asterisks. (Use for-loop to draw the asterisks, do not hard-coded)
Given a variable n refers to a positive int value, use two additional variables, k and total to write a for loop to compute the sum of the cubes of the first n counting numbers, and store this value in total. Thus your code should put 1*1*1 + 2*2*2 + 3*3*3 +... + n*n*n into total. Use no variables other than n, k, and total.
Java
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In Exercises 39 through 44, write a program to carry out the task. The form contains two text boxes into which ...
Introduction To Programming Using Visual Basic (11th Edition)
The spreadsheet in Microsoft Excel file Ch01Ex01_U10e.xlsx contains records of employee activity on special pro...
Using MIS (10th Edition)
Write an SQL query to list each customer who bought at least one product that belongs to product line Basic in ...
Modern Database Management
A dataset has 1000 records and 50 variables with 5% of the values missing, spread randomly throughout the recor...
Data Mining for Business Analytics: Concepts, Techniques, and Applications with XLMiner
Find and correct the error(s) in each of the following segments of code: The following code should output the e...
Java How To Program (Early Objects)
Pennies for Pay Design a program that calculates the amount of money a person would earn over a period of time ...
Starting Out with Programming Logic and Design (4th 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
- Output integer's digits Given an input positive integer, output each digit on its own line, starting with the rightmost digit. Ex: If the input is 935, the output is: 5 3 9 Hints: Use the mod operator (%) to get the rightmost digit. Mod by 10 to get the rightmost digit. Use a loop that keeps a current dividend (the number being divided). In each iteration, output the rightmost digit, then update the divisor by dividing by 10. End the loop when the divisor is 0. in javaarrow_forwardWrite a for loop that computes the sum of the integers from 1 to n. Get the value of n from the user.arrow_forwardWrite a loop of your choice that continues to read an integer x as long as x not divisible by 5 and 3. Complete the missing code in the space provided below. { int x=1; ............ }arrow_forward
- Program in JAVA using While Loop Write a program that takes a positive integer input and prints the numbers starting from input until 0 in one line where each numbers are separated by a space. Note: There's an initial code prepared for you. Go directly to the code editor file and complete the solution. Input 1. A positive integer input Output Enter a number: 5 5 4 3 2 1 0arrow_forwardsolve in java Integer numInput is read from input representing the number of integer values to be read next. Use a loop to read the remaining integer values from input. For each integer value read, output "Value read: " followed by the value. Then, output "Highest: " followed by the highest of the integer values read. End each output with a newline. Ex: If the input is: 3 220 -490 5 then the output is: Value read: 220 Value read: -490 Value read: 5 Highest: 220 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.Scanner; public class HighestValues { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intnumInput; intinputValue; inthighestVal=0; inti; numInput=scnr.nextInt(); /* Your code goes here */ } }arrow_forwardAsk the user how many integers that he/she wants to enter. Using a for loop, ask the user for that many integers. Then, display all those integers. use test case examples as a reference. Write code in Javaarrow_forward
- int is total, not totalthatarrow_forward/*code Kth Largest Factor A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive integers N and k, write a program to print the kth largest factor of N. Input Format: The input is a comma-separated list of positive integer pairs (N, k). Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1. Constraints: 1<N<10000000000 1<k<600. You can assume that N will have no prime factors which are larger than 13..arrow_forwardUsing a Java application write a for loop to sum all the squares of numbers between 1 and 15. Output the sum.arrow_forward
- Given int variables k and total that have already been declared, use a for loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no variables other than k and total.arrow_forwardPlease answer using a loop use while pleasearrow_forwardPythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY