Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( This is from Review Exercise R 4 . 1 at the end of Chapter 4 of Java for Everyone. ) Assume variables SimpleWriter out

(This is from Review Exercise R4.1 at the end of Chapter 4 of Java for Everyone.)
Assume variables SimpleWriter out and int n are already declared in each case. Write a separate while loop for each of the following tasks:
a. Print all squares less than n. For example, if n is 100, print 0149162536496481.??
b. Print all positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 102030405060708090?.
c. Print all powers of two less than n. For example, if n is 100, print 1248163264.
(The first four of these are from Review Exercise R4.3 at the end of Chapter 4 of Java for Everyone). Using the kind of tracing tables discussed in Writing and Tracing Loops, provide tracing tables for these loops:
a.
b.
c.
d.
e.
(This is from Review Exercise R4.15 at the end of Chapter 4 of Java for Everyone.) Rewrite the following for loop into a while loop.
Given variables int n and double pi, write a snippet of code that assigns to pi the approximation of resulting from adding the first n terms in the Gregory-Leibniz series:
=4i=0(-1)i2i+1=4(11-13+15-17+dots)
Given variables int areaBound and int sum, write a snippet of code that assigns to sum the result of adding up all integers of the form n2+m2 where:
@ both n and m are at least 1, and
@n2 areaBound, and
@m2 areaBound .
Additional Questions
Modify the loop to approximate pi with the Gregory-Leibniz series so that, instead of adding a given number of terms, it keeps adding terms until the difference between two consecutive estimates is less than some predefined tolerance, say double epsilon =0.0001.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Define organization development (OD)

Answered: 1 week ago