Concept explainers
What output is produced by the following code?
int[][] testArray = new int[3][4];
for (int row = 0; row < testArray.length; row++)
for (int col = 0;
col < testArray[row].length; col++)
testArray[row][col] = col;
for (int row = 0; row < testArray.length; row++)
{
for (int col = 0;
col < testArray[row].length; col++)
System.out.print(testArray[row][col] + " ");
system.out.println();
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
C Programming Language
Database Concepts (7th Edition)
- 8arrow_forward//Required Functionvoid func(int array_1[],int array_2[],int size){ for(int i=0;i<size;i++){ if(array_2[i]>array_1[i]){ array_1[i]=array_2[i]; } } return;} //main function to test the function.int main(){ int size=6; int a[]={1,5,9,8,7,6}; int b[]={1,4,10,12,7,15}; printf("First array before function call: "); for(int i=0;i<size;i++){ printf("%d ",a[i]); } func(a,b,size); //call to the created function printf("\nFirst array after function call: "); for(int i=0;i<size;i++){ printf("%d ",a[i]); } return 0;} 1. Write the statements to do the following: write a prototype for your function in the previous problem write a main function which includes the following steps declare two arrays of ints with 25 elements each prompt the user and read values into both arrays call your function from the previous problem print both arraysarrow_forwardThe following definition has errors. Locate as many as you can. A) void showValues(int nums) {for (int count = 0; count < 8; count++) cout << nums[count];}B) void showValues(int nums[4][]) {for (rows = 0; rows < 4; rows++) for (cols = 0; cols < 5; cols++)cout << nums[rows][cols];}arrow_forward
- java homeworkarrow_forward1. An array is a container that holds a group of values of a 2. Each item in an array is called an 3. Each element is accessed by a numerical 4. The index to the first element of an array is 0 and the index to the last element of the array is the length of the 5. Given the following array declaration, determine which of the three statements below it are true. int [] autoMobile = new int [13]; i. autoMobile[0] is the reference to the first element in the array. ii. autoMobile[13] is the reference to the last element in the array. ii. There are 13 integers in the autoMobile array. 6. In java new is a which is used to allocate memory 7. Declare a one-dimensional array named score of type int that can hold9 values. 8. Declare and initialize a one-dimensional byte array named values of size 10 so that all entries contain 1. 9. Declare and initialize a one-dimensional array to store name of any 3 students. 10. Declare a two-dimensional array named mark of type double that can hold 5x3…arrow_forward#include for(int i = 0; i { int main() for(int j = 0; j< 2; j++) { { int matrix[2][2] = { printf(" %d", matrix[i][j]); } {2,3,}, //rowo printf("\n"); } {5,7}//row1 getch(); }; } printf("\n Resultant \n"); Try to execute, screenshot the resul and try to explain the sequence of the program. Post it in space-ners provided. FRAMEWORK HTPE ADACHE e OrcE outATION roR TECHO A LEarrow_forward
- 2 #include 3 #include 4 5 6 7 8 void printArray(int myArr[][ARRAY_COLS]) 9- { 10 11- 12 13- const int ARRAY_COLS = 10; 3; const int ARRAY_ROWS 14 15 16 17 18 } 19 20- /* 21 26 27 } 37 } 38 44 45 46 47 48 49 50 for (int i = 0; i < ARRAY_ROWS; i++) { 22 23 */ 24 void zeroCorners (int myArr[] [ARRAY_COLS]) 25 - { myArr[0][0] = 999; 51 52 } This function currently sets the upper-left-hand corder of the 2D array to 999 Instead, this should set all 4 corners of the 2-D array to zero. for (int j = 0; j < ARRAY_COLS; j++) { std::cout << myArr[i][j] << ", "; } 28 29 - /* 30 This function should Loop through every element in the 2-D array. If an element is odd, then subtract one from to make it even. 31 32 HINT: function printArray() is an example of Looping through every element in 2D array */ 33 34 void makeEven (int myArr[][ARRAY_COLS]) 35 - { 36 // TODO - put code here std::cout << "\n"; 53 54 } 55 39 int main() 40 - { 41 - 42 43 int arr[][ARRAY_COLS] { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10),…arrow_forwarddef sum_threshold_2d_array(array, threshold):"""Iterate through each element of the 2d array using nested loops.Sum up the values that are greater than a threshold value given as an input parameter.:param array: a 2d array:param threshold: a threshold value (valid int or float):return: sum total of values above the threshold"""passarrow_forwardAssume that the following program segment is executed. What is the last element of testArray2 after the execution of the statement sortArray1(testArray2);? *arrow_forward
- 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