
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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;](https://content.bartleby.com/qna-images/question/507ffaff-36d6-4c89-a9b8-d054ae79319d/47fab9d6-4251-416c-8e8c-4df0f9574b3a/54qx1vl.png)
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 }](https://content.bartleby.com/qna-images/question/507ffaff-36d6-4c89-a9b8-d054ae79319d/47fab9d6-4251-416c-8e8c-4df0f9574b3a/eo3i4x.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images

Knowledge Booster
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
- Question 10 18 points Previous Next Fill in the blanks Given the array declaration below. Let i, j, k be the row, column and thickness indices respectively. intI00 num = {{{6,1,7),(-3,0,8}}, {{5,12,4),{20,-1,9}}, {{4,-22,11},{0,-7,3}}}; %3D There are rows, | columns and thickness. The elements on the first column, j=0, from top to bottom and on the same level, front to back are: The elements on the second thickness, k=1, from top to bottom and on the same level, left to right are:arrow_forwardQ1. What is the suffix array of the string "abbaba$"? You are not required to include cyclic rotations in your answer. Q2. What is the longest common prefix array of the string "abbaba$"? Assume that the longest common prefix between the empty string and any other string is of length 0.arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education