Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8.3, Problem 8.3.2CP
Show the output of the following code:
int[][] array = {{1, 2}, {3, 4}, {5, 6}};
int sum= 0 ;
for (int i = 0 ; i < array.length ; i++)
sum+= array[i] [0];
System.out.println(sum);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Print the elements of the array ‘a’ using the mentioned notations:
int a[]={1,2,3,4,5};
int *p;
p = a;
for (int i = 0; i< 5; i++)
{
//Subscript notation with name of array
//Subscript notation with pointer 'p'
//Offset notation using array name
//Offset notation using pointer 'p'
}
void mystery2(int list[], int length) { for (int i = 0; i < length - 1; i++) { if (i % 2 == 0) { list[i]++; } else { list[i]--; } }}
For each array below, indicate what the array's contents would be after the function were called and passed that array as its parameter. use the following as input.
{6, 3}
{2, 4, 6}
{1, 2, 3, 4}
{2, 2, 2, 2, 2}
{7, 3, 2, 0, 5, 1}
//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 arrays
Chapter 8 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 8.2 - Declare an array reference variable for a...Ch. 8.2 - Prob. 8.2.2CPCh. 8.2 - What is the output of the following code? int[] []...Ch. 8.2 - Which of the following statements are valid? int...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.4 - Show the output of the following code: public...Ch. 8.5 - Prob. 8.5.1CPCh. 8.6 - What happens if the input has only one point?Ch. 8.7 - What happens if the code in line 51 in Listing 8.4...
Ch. 8.8 - Declare an array variable for a three-dimensional...Ch. 8.8 - Assume char[][][] x =new char[12][5][2], how many...Ch. 8.8 - Show the output of the following code: int[][][]...Ch. 8 - (Sum elements column by column) Write a method...Ch. 8 - (Sum the major diagonal in a matrix) Write a...Ch. 8 - (Sort students on grades) Rewrite Listing 8.2,...Ch. 8 - (Compute the weekly hours for each employee)...Ch. 8 - (Algebra: add two matrices) Write a method to add...Ch. 8 - (Algebra: multiply two matrices) Write a method to...Ch. 8 - (Points nearest to each other) Listing 8.3 gives a...Ch. 8 - (All closest pairs of points) Revise Listing 8.3,...Ch. 8 - Prob. 8.9PECh. 8 - (Largest row and column) Write a program that...Ch. 8 - (Game: nine heads and tails) Nine coins are placed...Ch. 8 - (Financial application: compute tax) Rewrite...Ch. 8 - (Locate the largest element) Write the following...Ch. 8 - (Explore matrix) Write a program that prompts the...Ch. 8 - (Geometry: same line ?) Programming Exercise 6.39...Ch. 8 - (Sort two-dimensional array) Write a method to...Ch. 8 - (Financial tsunami) Banks lend money to each...Ch. 8 - (Shuffle rows) Write a method that shuffles the...Ch. 8 - (Pattern recognition: four consecutive equal...Ch. 8 - Prob. 8.20PECh. 8 - (Central city) Given a set of cities, the central...Ch. 8 - (Even number of 1s) Write a program that generates...Ch. 8 - (Game: find the flipped cell) Suppose you are...Ch. 8 - (Check Sudoku solution) Listing 8.4 checks whether...Ch. 8 - Prob. 8.25PECh. 8 - (Row sorting) Implement the following method to...Ch. 8 - (Column sorting) Implement the following method to...Ch. 8 - (Strictly identical arrays) The two-dimensional...Ch. 8 - (Identical arrays) The two-dimensional arrays m1...Ch. 8 - (Algebra: solve linear equations) Write a method...Ch. 8 - (Geometry: intersecting point) Write a method that...Ch. 8 - (Geometry: area of a triangle) Write a method that...Ch. 8 - (Geometry: polygon subareas) A convex four-vertex...Ch. 8 - (Geometry: rightmost lowest point) In...Ch. 8 - (Largest block) Given a square matrix with the...Ch. 8 - (Latin square) A Latin square is an n-by-n array...Ch. 8 - (Guess the capitals) Write a program that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Find out if your compiler supports variable-length arrays. If it does, write a small program to test the featur...
Programming in C
True or False: A class may not have more than one constructor.
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Write a database description for each of the relations shown, using SQL DOL (shorten, abbreviate. or change any...
Modern Database Management
Repeat Programming Project 11 from Chapter 10 but use an array to store the movie ratings instead of separate v...
Problem Solving with C++ (10th Edition)
Write a loop equivalent to the for loop above without using .
C Programming Language
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
- 2. How do you initialize an array in C? a) int arr[3] = (1,2,3); b) int arr(3) = {1,2,3}; c) int arr[3] = {1,2,3}; d) int arr(3) = (1,2,3);arrow_forwardint X[10]={2,0,6,11,4,5,9,11,-2,-1); From the code above, what is the value of X[8] ?arrow_forwardint [] arrayInt={3,54,90,22,32}; To print the last element in the arrayInt you will write: a. System.out.println(arrayInt[5]); b. System.out.println(arrayInt[0]); c. System.out.println(arrayInt[length]); d. System.out.println(arrayInt[4]);arrow_forward
- void showArray ( int a[ ], int size ); // shows the array in the format "int a [ ] = { 3, 7, 4, ... ,5, 6, 3} void showReverse ( int a[ ], int size ); // shows the array in reverse "int a [ ] = { 3, 6, 5, ... , 4, 7, 3 } " int lowest ( int a[ ], int size ); // finds and returns the lowest value in the array (should be 3) int highest ( int a[ ], int size ); // finds and returns the highest value in the array (should be 7) int sumArray ( int a[ ], int size ); // calculates and returns the sum of all values in the array float averageVal ( int a[ ], int size ); // calculates and returns the average of all values in the array int count5 ( int a[ ], int size ); // returns how many times the number 5 appears in the array int firstMinusLast ( int a[ ], int size ); // returns the difference b/w the First and Last Array Element void showBeforeIndex( int a [ ], int index); // shows all array values before a specific index void done…arrow_forwardint[] cars = {1,2,3,4,5}; for (int i=0; iarrow_forward//convert array of numbers from farenheit to celcius// example:// argument: [23, 32, 41, 50, 59]// return: [-5, 0, 5, 10, 15]// hint: use Array.mapfunction toCelcius(array){ } //write a function that takes an input array and returns an array of booleans (>=75) or fail (<75)// example:// argument: [20, 30, 50, 80, 90, 100]// return: [false, false, false, true, true, true]// hint: use Array.mapfunction passOrFail(array){ }arrow_forwardHow do you initialize an array in C? a. int arr[3] = (1,2,3); b. int arr(3) = {1,2,3}; C. int arr(3) = [1,2,3]; Od. int arr[3] = {1,2,3};arrow_forward84. Refer to the following method that finds the largest value in an array. /** Precondition: arr is initialized with int values. * @param arr the array to be processed * @return the largest value in arr */ public static int findMax(int[] arr) { int max = /* some value */; 0; int index %3D while (index max) arr[index]; max = index++; return max; } Which replacement(s) for /* some value */ will always result in correct execution of the findMax method? Integer. MIN _VALUE III. I. II. Integer.MAX_VALUE arr[0]arrow_forwardJAVA PROGRAM: Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 5 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey, or use constant values rather than asking user for input. Then it should create a report that includes the following information: Display 3X5 array first. Average amount of food eaten per day by the whole family of The least amount of food eaten during the week by any one The greatest amount of food eaten during the week by any one Input Validation: Do not accept negative numbers for pounds of food eaten.arrow_forwardpublic int[] bubbleSort(int[] array) {int n = array.length;int temp = 0;}arrow_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#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_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
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
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License