Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
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
Write a loop that finds the smallest value. Print it and the index code format: #include <iostream>using namespace std; #include <cstdlib> // required for rand() int main(){// Put Part2 code here // Declare smallestFoundSoFar// Q: what should be its initial value?int indexOfSmallest = -1;// sign that it is not initialized Part 2 code #include <iostream> using namespace std; // part 1 code#include <cstdlib>   int main() { srand(17); const int ARRAYSIZE = 20; // size for the array int RandArray[ARRAYSIZE]; // array declared int i; // to iterate the loop   // this loop will store thei random number in the array for (i = 0; i < ARRAYSIZE; i++) RandArray[i] = rand() % 100;   // this loop will print the array for (i = 0; i < ARRAYSIZE; i++) cout <<"randArray["<< i <<"]=" << RandArray[i] << endl;   int largestFoundSoFar=-1; // anything is larger than this! int indexOfLargest = -1; // sign that it is not initialized   for (i = 0; i…
The following program reads a comma separated value (CSV) file of student grades. Each line of the file contains two values: the student ID and the grade. For example ID534240025, A- Complete the following loop that reads the file and extracts the two values into the variables student and grade. infile = open("studentList.csv") for line in infile: line line.strip() student, grade = =
#include <stdio.h> #include <string.h> int IsPasswordOkay(char* pass) { char Password[12]; strcpy(Password, pass); if (!strcmp(Password, "goodpass")) return(1); else return(0); } int main(int argc, char **argv) { int PwStatus; if (argc < 2) { printf("Input your password\n"); return(-1); } PwStatus = IsPasswordOkay(argv[1]); if (PwStatus == 0) { printf("Acces denied"); return(-1); } else { printf("Access granted"); return(1); } } Write a function to conduct input validation to secure the smallest buffer. You may call this function void SecurePasswordBuffer(const char *arg).

Chapter 30 Solutions

Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education