Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 30.3, Problem 30.3.2CP

Explanation of Solution

Purpose of given code:

Purpose of given code is to display the count value, maximum value, minimum value, sum value, and average value of integer array “numbers”.

Given code:

//Variable definition

int[] numbers = {1, 4, 2, 3, 1};

/*Error #1*/

DoubleSummaryStatistics stats = DoubleStream.of(numbers).summaryStatistics();

/*Print statement with aggregate functions*/

/*Error #2*/

System.out.printf("The summary of the stream is\n%-10s%10d\n" +"%-10s%10.2f\n%-10s%10.2f\n%-10s%10.2f\n%-10s%10.2f\n","  Count:", stats.getCount(), "  Max:", stats.getMax(),"  Min:", stats.getMin(), "  Sum:", stats.getSum(),"  Average:", stats.getAverage());

Error #1:

The values of variable “numbers” are in “int” array. The above program uses “DoubleSummaryStatistics” instead of “IntSummaryStatistics”.

Error #2:

The resultant minimum, maximum, and sum value is integer...

Blurred answer
Students have asked these similar questions
Consider a text file of names, with one name per line, that has been compiled from several different sources. A sample is shown below:Brooke TroutDinah SoarsJed DyeBrooke TroutJed DyePaige TurnerThere are duplicate names in the file. We would like to generate aninvitation list but don’t want to send multiple invitations to the sameperson. Write a program that eliminates the duplicate names by usinga HashSet. Read each name from the file, add it to the HashSet, andthen output all names in the HashSet to generate the invitation listwithout duplicates
OCaml Code: Below is streams.ml and it needs the value "head". Please fix the code and make sure to test the code using various test cases to make sure the code works.  streams.ml let rec even n =  if n = 0 then true  else odd (n - 1)and odd n =  if n = 0 then false  else even (n - 1) let rec squares n =  let rec squares_aux m acc =    if m = 0 then List.rev acc    else squares_aux (m - 1) (acc @ [m * m])  in  squares_aux n []   let rec fibs n =  let rec fibs_aux a b count acc =    if count = 0 then List.rev acc    else fibs_aux b (a + b) (count - 1) (a :: acc)  in  fibs_aux 0 1 n [] let rec evenFibs n =  let rec fibs_aux a b count acc =    if count = 0 then List.rev acc    else if a mod 2 = 0 then fibs_aux b (a + b) (count - 1) (a :: acc)    else fibs_aux b (a + b) count acc  in  fibs_aux 0 1 n [] let rec oddFibs n =  let rec fibs_aux a b count acc =    if count = 0 then List.rev acc    else if a mod 2 = 1 then fibs_aux b (a + b) (count - 1) (a :: acc)    else fibs_aux b (a + b) count…
At the interactive prompt, define a list named L that contains four strings or numbers (e.g., L=[0,1,2,3]).a. What happens when you try to index out of bounds(e.g.,L[4])?b. What about slicing out of bounds (e.g.,L[-1000:100])?c. Finally, how does Python handle it if you try to extract a sequence inreverse—with the lower bound greater than the higher bound (e.g., L[3:1])? Hint: try assigning to this slice(L[3:1]=[‘?’]) and see where the value is put.

Chapter 30 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning