2D array, Passing Arrays to Methods, Returning an Array from a Method (Ch8) 2. Read-And-Analyze: Given the code below, answer the following questions. 2 1 import java.util.Scanner; 3 public class Array2DPractice { 4 5 6 7 8 9 10 11 12 13 14 15 16 public static void main(String args[]) { 17 } 18 // Get an array from the user int[][] m = getArray(); // Display array elements System.out.println("You provided the following array "+ java.util.Arrays.deepToString(m)); // Display array characteristics int[] r = findCharacteristics(m); System.out.println("The minimum value is: " + r[0]); System.out.println("The maximum value is: " + r[1]); System.out.println("The average is: " + r[2] * 1.0/(m.length * m[0].length)); 19 // Create an array from user input public static int[][] getArray() { 20 21 PASSTR2222322222222222 222323 F F F F 44 // Create a Scanner to read user input Scanner input = new Scanner(System.in); // Ask user to input a number, and grab that number with the Scanner System.out.println("Please enter the amount of rows you would like: "); int rowAmount = input.nextInt(); System.out.println("Please enter the amount of columns you would like: "); int colAmount = input.nextInt(); // Create the array int[][]m-new int[rowAmount][colAmount]; 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 input.close() 41 42 return m; 43 System.out.println("With spaces to split the numbers, and shift+enter to start a new row, enter a matrix and press enter."); for(int row = 0; row max) max = element; 58 59 sum += element; 60 61 63 64 // Create new array to store characteristics int[] c = new int[3]; 65 c[0] = min; 66 c[1] = max; 67 c[2] = sum; 68 69 70 } return c; 71} 2-0. What does the code do? (this can be a general answer) 2-1. When ran, what is going to be the size of the 2D array m? # rows? # columns? (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's the difference between m.length and m[0].length? (lines 16) 2-5. Can you explain how the average was calculated? And how was the sum calculated? (line 16,59)
2D array, Passing Arrays to Methods, Returning an Array from a Method (Ch8) 2. Read-And-Analyze: Given the code below, answer the following questions. 2 1 import java.util.Scanner; 3 public class Array2DPractice { 4 5 6 7 8 9 10 11 12 13 14 15 16 public static void main(String args[]) { 17 } 18 // Get an array from the user int[][] m = getArray(); // Display array elements System.out.println("You provided the following array "+ java.util.Arrays.deepToString(m)); // Display array characteristics int[] r = findCharacteristics(m); System.out.println("The minimum value is: " + r[0]); System.out.println("The maximum value is: " + r[1]); System.out.println("The average is: " + r[2] * 1.0/(m.length * m[0].length)); 19 // Create an array from user input public static int[][] getArray() { 20 21 PASSTR2222322222222222 222323 F F F F 44 // Create a Scanner to read user input Scanner input = new Scanner(System.in); // Ask user to input a number, and grab that number with the Scanner System.out.println("Please enter the amount of rows you would like: "); int rowAmount = input.nextInt(); System.out.println("Please enter the amount of columns you would like: "); int colAmount = input.nextInt(); // Create the array int[][]m-new int[rowAmount][colAmount]; 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 input.close() 41 42 return m; 43 System.out.println("With spaces to split the numbers, and shift+enter to start a new row, enter a matrix and press enter."); for(int row = 0; row max) max = element; 58 59 sum += element; 60 61 63 64 // Create new array to store characteristics int[] c = new int[3]; 65 c[0] = min; 66 c[1] = max; 67 c[2] = sum; 68 69 70 } return c; 71} 2-0. What does the code do? (this can be a general answer) 2-1. When ran, what is going to be the size of the 2D array m? # rows? # columns? (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's the difference between m.length and m[0].length? (lines 16) 2-5. Can you explain how the average was calculated? And how was the sum calculated? (line 16,59)
Chapter7: Using Methods
Section: Chapter Questions
Problem 20RQ
Related questions
Question
![2D array, Passing Arrays to Methods, Returning an Array from a Method (Ch8)
2. Read-And-Analyze: Given the code below, answer the following questions.
2
1 import java.util.Scanner;
3 public class Array2DPractice {
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void main(String args[]) {
17 }
18
// Get an array from the user
int[][] m = getArray();
// Display array elements
System.out.println("You provided the following array "+ java.util.Arrays.deepToString(m));
// Display array characteristics
int[] r = findCharacteristics(m);
System.out.println("The minimum value is: " + r[0]);
System.out.println("The maximum value is: " + r[1]);
System.out.println("The average is: " + r[2] * 1.0/(m.length * m[0].length));
19 // Create an array from user input
public static int[][] getArray() {
20
21
PASSTR2222322222222222 222323 F F F F
44
// Create a Scanner to read user input
Scanner input = new Scanner(System.in);
// Ask user to input a number, and grab that number with the Scanner
System.out.println("Please enter the amount of rows you would like: ");
int rowAmount = input.nextInt();
System.out.println("Please enter the amount of columns you would like: ");
int colAmount = input.nextInt();
// Create the array
int[][]m-new int[rowAmount][colAmount];
24
25
26
27
28
29
30
31
33
34
35
36
37
38
39
40
input.close()
41
42
return m;
43
System.out.println("With spaces to split the numbers, and shift+enter to start a new row, enter a matrix and
press enter.");
for(int row = 0; row <m.length; row++)
for(int col = 0; col <m[row].length; col++)
m[row][col]-input.nextInt();](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1f1cff89-d0c3-401a-ba77-d9b5f81fcda4%2Ffc50b6d7-86ff-427c-b760-5f50d1d5c43a%2Fnlcbprf_processed.png&w=3840&q=75)
Transcribed Image Text:2D array, Passing Arrays to Methods, Returning an Array from a Method (Ch8)
2. Read-And-Analyze: Given the code below, answer the following questions.
2
1 import java.util.Scanner;
3 public class Array2DPractice {
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void main(String args[]) {
17 }
18
// Get an array from the user
int[][] m = getArray();
// Display array elements
System.out.println("You provided the following array "+ java.util.Arrays.deepToString(m));
// Display array characteristics
int[] r = findCharacteristics(m);
System.out.println("The minimum value is: " + r[0]);
System.out.println("The maximum value is: " + r[1]);
System.out.println("The average is: " + r[2] * 1.0/(m.length * m[0].length));
19 // Create an array from user input
public static int[][] getArray() {
20
21
PASSTR2222322222222222 222323 F F F F
44
// Create a Scanner to read user input
Scanner input = new Scanner(System.in);
// Ask user to input a number, and grab that number with the Scanner
System.out.println("Please enter the amount of rows you would like: ");
int rowAmount = input.nextInt();
System.out.println("Please enter the amount of columns you would like: ");
int colAmount = input.nextInt();
// Create the array
int[][]m-new int[rowAmount][colAmount];
24
25
26
27
28
29
30
31
33
34
35
36
37
38
39
40
input.close()
41
42
return m;
43
System.out.println("With spaces to split the numbers, and shift+enter to start a new row, enter a matrix and
press enter.");
for(int row = 0; row <m.length; row++)
for(int col = 0; col <m[row].length; col++)
m[row][col]-input.nextInt();
![45
46
47
48
49
50
51
52
53
54
55
56
57
=ཟཋ❁༢R62gརྩ⌘*g ུ་ཅཆེདྭི$ཆེ
// Given an array, this method finds its characteristics and returns an array
public static int[] findCharacteristics (int[][] m) {
int min = m[0][0];
int max = m[0][0];
int sum = 0;
for(int[] array: m) {
for(int element array) {
if(element <min)
min = element;
if(element> max)
max = element;
58
59
sum += element;
60
61
63
64
// Create new array to store characteristics
int[] c = new int[3];
65
c[0] = min;
66
c[1] = max;
67
c[2] = sum;
68
69
70
}
return c;
71}
2-0. What does the code do? (this can be a general answer)
2-1. When ran, what is going to be the size of the 2D array m? # rows? # columns? (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's the difference between m.length and m[0].length? (lines 16)
2-5. Can you explain how the average was calculated? And how was the sum calculated? (line
16,59)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1f1cff89-d0c3-401a-ba77-d9b5f81fcda4%2Ffc50b6d7-86ff-427c-b760-5f50d1d5c43a%2Fs6bqpro_processed.png&w=3840&q=75)
Transcribed Image Text:45
46
47
48
49
50
51
52
53
54
55
56
57
=ཟཋ❁༢R62gརྩ⌘*g ུ་ཅཆེདྭི$ཆེ
// Given an array, this method finds its characteristics and returns an array
public static int[] findCharacteristics (int[][] m) {
int min = m[0][0];
int max = m[0][0];
int sum = 0;
for(int[] array: m) {
for(int element array) {
if(element <min)
min = element;
if(element> max)
max = element;
58
59
sum += element;
60
61
63
64
// Create new array to store characteristics
int[] c = new int[3];
65
c[0] = min;
66
c[1] = max;
67
c[2] = sum;
68
69
70
}
return c;
71}
2-0. What does the code do? (this can be a general answer)
2-1. When ran, what is going to be the size of the 2D array m? # rows? # columns? (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's the difference between m.length and m[0].length? (lines 16)
2-5. Can you explain how the average was calculated? And how was the sum calculated? (line
16,59)
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

Recommended textbooks for you

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning