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)
- В.width; } { t = B.type; w = { T.type = C.type; T.width = C.width; } T → B C В > int { B.type = integer; B.width 4; } В — foat { B.type = float; B.width = 8; } { C.type = t; C.width = w; } C - [ num] C1 = array(num. value, C1.type); { C.type C.width = num. value x C1. width; }arrow_forward#include <stdio.h>int counter=0;int size;void deleteNumber(int array[],int index);void insertNumber(int array[],int index,int value);void insertIntelligently(int array[],int number);void insertByvalue(int array[]);void deleteByrange(int array[]);void search(int array[]);void ascendingOrder(int array[]);void descendingOrder(int array[]);void replace(int array[]);void printArray(int array[]);int main() {int array[size], choice, i;printf("Enter size of the array");scanf("%d", &size);for (i = 0; i < size; i++) {printf("Enter the value for Index %d: ", i);scanf("%d", &array[i]);printf("\n");counter++;printf("%d", counter);}printArray(array);printf("\nCounter is: %d \n", counter);printf("\n");while (choice != 9) {printf("\n\nPress '1' to Insert by Index and Value \nPress '2' to Delete \nPress '3' to Insert by Value\nPress '4' to Delete By Range\nPress '5' to replace a value\nPress '6' to search a number\nPress '7' to print in ascending order\nPress '8' to print in descending…arrow_forwardint A[3] [4]={{ 4, 6, 7, 9},{ 1, 3, 4, 3},{-5, 6, 7, 2}}; int sum, row, col; sum = 0; for (col=0;col<=3;i++) sum+=A[0] [col]; what is the value of sum calculated the number of elements on row 0 the total addition of elements on row 0 the total addition of first 3 elements on row 0 the total addition of all the elementsarrow_forward
- If you have the following statements: int i j; int ctr = 0; int myArray[2][3]; for (i=0; i<3; i++) for (j=0; j<2; j++) { myArray[ j ][ i] = ctr; ++ctr; } The value of the element myArray[1][2] after executing the above statements:arrow_forward3. Implement a function called findLargestIndex which returns the index of the rowwith the largest sum.ex. int array[3][6] = {{3, 6, 8, 2, 4, 1}, // sum = 24{2, 4, 5, 1, 3, 4}, // sum = 19{1, 0, 9, 0, 1, 0}}; // sum = 11If the findLargestIndex function was called using this array, it would return 0, asit is returning the index of the row, not the sum.Note that the number of columns is required when passing a 2d array to a function.Assume that 2D arrays passed to this function will have 6 columns.Title line: int findLargestIndex(int array[][6], int rows, int columns);arrow_forwardBelow is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and createThe loop below stores the values 1 to 5 in myList:for (int i = 0; i < 5; i ++) {myList [ i ] = i + 1; //store values using a loop}The loop below prints the values from first to last in myList:for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " ");}The code below is used to get user from the user and calculate the sum:import java.util.*;public class WhileWithInput {public static void main(String[] args) {Scanner reader = new Scanner (System.in);int count = 1; double total = 0; while (count <= 5) {System.out.println("Enter a decimal number"); double number = reader.nextDouble();total = total + number;count = count + 1;System.out.println("The total is " + total); }System.out.println("The total is " + total); }}1CPS 2231 Chapter 7 – lab 2 Fall 2019Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor…arrow_forward
- def clipping_2d_array(array, threshold):"""Iterate through each element of the 2d array using nested loops.Set the values greater than a threshold value equal to the threshold value given as an input parameter.(E.g. if the threshold is 1 and there is a value 1.5, set the value to 1 in the array):param array: a 2d array:param threshold: a threshold value (valid int or float)"""passarrow_forwardWhat values would be stored in the array "data" after the following code executes:int[] data = new int[7];data[0] = 3;data[6] = -18;data[4] = 5;data[1] = data[0];int x = data[4];data[4] = 6;data[2] = x;data[3]= data[2]-1;arrow_forwardBelow is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and create The loop below stores the values 1 to 5 in myList: for (int i = 0; i< 5; i++) { myList [i] =i+1; //store values using a loop The loop below prints the values from first to last in myList: for (int i = 0; i< myList.length; i++) { System.out.print(myList [i]+""); The code below is used to get user from the user and calculate the sum: import java.util."; public class WhileWithInput { public static void main(String[] args) { Scanner reader = new Scanner (System.in); int count = 1; double total = 0; while (count <= 5) { System.out.println("Enter a decimal number"); double number = reader.nextDouble(); total = total + number; count = count + 1; System.out.printlin("The total is "+ total); } System.out.println("The total is "+ total); } 1 CPS 2231 Chapter 7- lab 2 Fall 2019 Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor showing…arrow_forward
- Functions with 2D Arrays in Java Write a function named displayElements that takes a two-dimensional array, the size of its rows and columns, then prints every element of a two-dimensional array. Separate every row by a new line and every column by a space. In the main function, call the displayElements function and pass in the required parameters. Output 1 2 3 4 5 6 7 8 9arrow_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//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_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