Write java statements that inputs two integers (n and k) entered by the user, generate n random double numbers in a range [0, 100], then calculate the followings: Sum of these numbers, Average of these numbers, • Average of their square roots, • Round these numbers to specified decimals k, find average of rounded numbers. One of the methods to round a double number to k decimal places is by using a DecimalFormat object and format method: import java.text.DecimalFormat; String formatStr = "#. ###"; DecimalFormat df = new DecimalFormat (formatStr); double rounded_number = Double.valueOf (df.format (random_number)); // round 3 decimal places If you use this method, before generating numbers, you must create appropriate formatStr by appending k times "#" to the end of "#.", and then create the DecimalFormat object. Then in the loop, you can use the last line above to obtain rounded number from randomly generated number. Part-3: Please enter n value: 5 Please enter k value: 4 5 random double numbers and rounded numbers are: 25.716196637192358 25.7162 42.032460307612574 42.0325 87.99224543639619 87.9922 89.22034753050279 89.2203 40.07050434213685 40.0705 Sum of these numbers: 285.0317542538408 Average of these numbers: 57.00635085076816 Average of their square roots: 7.342111149903732 Average of these numbers by rounding them to 4 decimals: 57.00634
Write java statements that inputs two integers (n and k) entered by the user, generate n random double numbers in a range [0, 100], then calculate the followings: Sum of these numbers, Average of these numbers, • Average of their square roots, • Round these numbers to specified decimals k, find average of rounded numbers. One of the methods to round a double number to k decimal places is by using a DecimalFormat object and format method: import java.text.DecimalFormat; String formatStr = "#. ###"; DecimalFormat df = new DecimalFormat (formatStr); double rounded_number = Double.valueOf (df.format (random_number)); // round 3 decimal places If you use this method, before generating numbers, you must create appropriate formatStr by appending k times "#" to the end of "#.", and then create the DecimalFormat object. Then in the loop, you can use the last line above to obtain rounded number from randomly generated number. Part-3: Please enter n value: 5 Please enter k value: 4 5 random double numbers and rounded numbers are: 25.716196637192358 25.7162 42.032460307612574 42.0325 87.99224543639619 87.9922 89.22034753050279 89.2203 40.07050434213685 40.0705 Sum of these numbers: 285.0317542538408 Average of these numbers: 57.00635085076816 Average of their square roots: 7.342111149903732 Average of these numbers by rounding them to 4 decimals: 57.00634
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Can you write java code according to the conditions ?
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY