Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*Each question must be done in Java* 1. Generate simple statistics and averages. Write a program that reads an unspecified number of integers. It stops

*Each question must be done in Java*

1. Generate simple statistics and averages. Write a program that reads an unspecified number of integers. It stops reading when it encounters a 0. Report the number of positve integers, the number of negative integers, the sum of all integers, and the average.

Example: Enter one or more integers, input is terminated by 0: 1 2 -1 3 0

The number of positives is 3

The number of negatives is 1

Their total is 5.0

Their average is 1.25

Example: Enter one or more integers, input is terminated by 0: 0

No numbers were entered other than 0.

2. Knowing that 1 kg = 2.2 lbs, write a program to create the following table: (Note carefully at the pattern and end condition)

Kilograms Pounds

1 2.2

3 6.6

... (Many rows omitted)

197 433.4

199 437.8

3. Knowing that 1 kg = 2.2 lbs, write a program to create the following tables side by side.

Bonus points if you research System.out.printf() for formatted output and give me a well formatted table!

Kilograms Pounds | Pounds Kilograms

1 2.2 | 20 9.09

3 6.6 | 25 11.36

... (Many rows omitted)

197 433.4 | 510 231.82

199 437.8 | 515 234.09

4. Approximate PI: PI can be approximated by the series: 4 * ( 1 - 1/3 + 1/5 - 1/7 + ... + (-1)^(i+1) / (2*i - 1) )

Note a^b here means a to the b power.

Write a program that calculates PI for i = 10_000, i = 20_000, and i = 100_000

Developer Note: Does that summation start with 0 , 1, or some other value of i?

5. Write a guessing game. Have your program generate a random integer between 1 and 10 inclusive.

Hint: int myRandom = (int)( 10 * Math.random() + 1 ) since Math.random() returns between 0.0 and 0.99999999...

Prompt the user to make their guess.

Respond by letting them know if they are too high, too low, or guessed correctly.

Put all the above logic inside a second loop. In this second, outer loop you can then ask the user if they want to play again or exit the program.

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

Step: 3

blur-text-image

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 In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Discuss shift hand-off report.

Answered: 1 week ago

Question

Describe important components of self-regulated learning.

Answered: 1 week ago