1 import java.util.Scanner; 2 3 public class Pass2D { public static void main(String[] args) { 4 // Get an array from the user int[][] m = getArray(); 6 %3D // Display array elements System.out.println("\nYou provided the following array " + java.util.Arrays.deepToString(m)); %3D 10 11 // Display array characteristics int [] r = findCharacteristics (m); System.out.println("\nThe minimum value is: 12 13 14 + r[0] + ", the maximum value is: the average is: + r[1] + + r[2] * 1.0/ (m.length %3D 15 m[0].length)); %3D 16 17 } 18 19 // this method finds array characteristics 20 public static int[] findCharacteristics(int[][] m) { 21 int min m[0][0]; %3D int max = m[0][0]; int sum = 0; 22 %3D 23 for (int [] arr m) for (int element : arr) { if (element < min) min = element; if (element > max) max = element; sum += element; 24 25 26 27 28 29 30 //create a new array to be returned int[] c = new int[3]; c[0] = min; c[1] = max; C[2] = sum; 31 32 33 34 35 36 37 return c; 38 39 40 // this method creates an array based on the user input 41 public static int[][] getArray() { // Create a Scanner Scanner input = new Scanner(System.in); System.out.println("Provide an integer for a number of rows: "); int row = input.nextInt(); 42 43 44 45 46 System.out.println("Provide an integer for a number of columns: "); int col = input.nextInt(); 47 48 49 // Create an array int[][] m = new int[row][col]; System.out.println("Enter a for (int i = 0; i < m.length; i++) for (int j = 0; j < m[i].length; j++) 50 51 %3D matrix and press Enter: "); %3D 52 + m.length + "x" + m[0].length + 53 54 %3D 55 m[i][j] = input.nextInt(); %3D 56 57 input.close(); 58 59 return m; 60 } 61 }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

2. See the code below and solve the following.

2-1.What is/are the dimension(s) of the array m? (line 7)

2-2.What is the length of the array r? (line 13)

2-3.What does r[2] represent? (line 16)

2-4. What does m[0].length stands for? (lines 16, 54)

2-5. Can you explain how the average was calculated? (line 16)

1 import java.util.Scanner;
2
3 public class Pass2D {
public static void main(String[] args) {
4
// Get an array from the user
int[][] m = getArray();
6
%3D
// Display array elements
System.out.println("\nYou provided the following array " + java.util.Arrays.deepToString(m));
%3D
10
11
// Display array characteristics
int [] r = findCharacteristics (m);
System.out.println("\nThe minimum value is:
12
13
14
+ r[0] +
", the maximum value is:
the average is:
+ r[1] +
+ r[2] * 1.0/ (m.length
%3D
15
m[0].length));
%3D
16
17 }
18
19 // this method finds array characteristics
20 public static int[] findCharacteristics(int[][] m) {
21
int min
m[0][0];
%3D
int max = m[0][0];
int sum = 0;
22
%3D
23
for (int [] arr m)
for (int element : arr) {
if (element < min) min = element;
if (element > max) max = element;
sum += element;
24
25
26
27
28
29
30
//create a new array to be returned
int[] c = new int[3];
c[0] = min;
c[1] = max;
C[2] = sum;
31
32
33
34
35
36
37
return c;
Transcribed Image Text:1 import java.util.Scanner; 2 3 public class Pass2D { public static void main(String[] args) { 4 // Get an array from the user int[][] m = getArray(); 6 %3D // Display array elements System.out.println("\nYou provided the following array " + java.util.Arrays.deepToString(m)); %3D 10 11 // Display array characteristics int [] r = findCharacteristics (m); System.out.println("\nThe minimum value is: 12 13 14 + r[0] + ", the maximum value is: the average is: + r[1] + + r[2] * 1.0/ (m.length %3D 15 m[0].length)); %3D 16 17 } 18 19 // this method finds array characteristics 20 public static int[] findCharacteristics(int[][] m) { 21 int min m[0][0]; %3D int max = m[0][0]; int sum = 0; 22 %3D 23 for (int [] arr m) for (int element : arr) { if (element < min) min = element; if (element > max) max = element; sum += element; 24 25 26 27 28 29 30 //create a new array to be returned int[] c = new int[3]; c[0] = min; c[1] = max; C[2] = sum; 31 32 33 34 35 36 37 return c;
38
39
40 // this method creates an array based on the user input
41 public static int[][] getArray() {
// Create a Scanner
Scanner input = new Scanner(System.in);
System.out.println("Provide an integer for a number of rows: ");
int row = input.nextInt();
42
43
44
45
46
System.out.println("Provide an integer for a number of columns: ");
int col = input.nextInt();
47
48
49
// Create an array
int[][] m = new int[row][col];
System.out.println("Enter a
for (int i = 0; i < m.length; i++)
for (int j = 0; j < m[i].length; j++)
50
51
%3D
matrix and press Enter: ");
%3D
52
+ m.length + "x"
+ m[0].length +
53
54
%3D
55
m[i][j] = input.nextInt();
%3D
56
57
input.close();
58
59
return m;
60 }
61 }
Transcribed Image Text:38 39 40 // this method creates an array based on the user input 41 public static int[][] getArray() { // Create a Scanner Scanner input = new Scanner(System.in); System.out.println("Provide an integer for a number of rows: "); int row = input.nextInt(); 42 43 44 45 46 System.out.println("Provide an integer for a number of columns: "); int col = input.nextInt(); 47 48 49 // Create an array int[][] m = new int[row][col]; System.out.println("Enter a for (int i = 0; i < m.length; i++) for (int j = 0; j < m[i].length; j++) 50 51 %3D matrix and press Enter: "); %3D 52 + m.length + "x" + m[0].length + 53 54 %3D 55 m[i][j] = input.nextInt(); %3D 56 57 input.close(); 58 59 return m; 60 } 61 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

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