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.4, Problem 8.4.1CP
Show the output of the following code:
public class Test {
public static void main(String[] args) {
int[][] array= {{1, 2, 3, 4}, {5, 6, 7, 8}};
System.out . println (m1(array)[0]);
System.out . println(m1(array)[1]) ;
public static int [] m1 (int[][] m) {
int[] result = new int[2] ;
result[0] = m.length;
result[1] = m[0] .length ;
return result ;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
6. Show the printout of the following code:
public class ArraysBasic {
public static void main(String[] args) {
int A[] = {1, 2, 3};
}
System.out.println("array A: " + A[0] +""+A[1]+""+ A[2]);
System.out.println("array
B: " + A[0] + " " + A[1] + " " + A[2]);
zeroArray(A);
A = new int[5];
System.out.println("array C: " + A[0] + " " + A[1] + " " + A[3] + " " +
A[4]);
}
}
public static void zeroArray(int[] list) {
for (int j = 0; j < list.length; ++j) {
list[j] = 99;
Complete this ap.
Analyze the following code.
public class Test {
public static void main (String ] args) {
int [] [] matrix = {{3, 2}, (7, 9, 5},{4, 8, 2, 6}};
System.out.-println ("matrix[1] [3] is " + matrix[1] [3]);
}
The program has a compile erTor because the size of the array wasn't specified.
O The program runs fine and displays
matrix[1][3] is 5.
The program has a runtime error because the index is out of the array bounds.
O The program runs fine and displays matrix[1][3] is 0.
Click Save and Submit to save and submit. Click Save All Answers to save all answers
hp
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
Given that y=ax3+7, which of the following are correct Java statements for this equations? int y = a (x x x)...
Java How To Program (Early Objects)
Find out if your compiler supports variable-length arrays. If it does, write a small program to test the featur...
Programming in C
What is a compiler?
Starting Out with Java: From Control Structures through Objects (6th Edition)
How high can you count with four decimal digits?
Digital Fundamentals (11th Edition)
Explain the different aspects of the cost of a programming language.
Concepts Of Programming Languages
Give three statements that will write the values of the three double variables x1, x2, and x3 to the file stuff...
Java: An Introduction to Problem Solving and Programming (8th Edition)
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
- public class ArrayMerge { static void arrayMerge(int a[], int b[]){ int c[] = new int[50]; int k = 0; for(int i = 0; i < a.length; i++) { c[k++] = a[i]; } for(int i = 0; i < b.length; i++) { c[k++] = b[i]; } for(int i = 0; i < k; i++) { System.out.println(c[i]); } } public static void main(String[] args) { int a[] = { 18, 36, 41, 78, 56 }; int b[] = { 10, 37, 44 }; arrayMerge(a,b); } } Calculate the algorithm step number and algorithm time complexity of the above program?arrow_forwardimport java.util.* ; public class Averager { public static void main(String[] args) { //a two dimensional array int[][] a = {{5, 9, 3, 2, 14}, {77, 44, 22, 15, 99}, {14, 2, 3, 9, 5}, {88, 15, 17, 121, 33}} ; System.out.printf("Average = %.2f\n", average(a)) ; System.out.println("EXPECTED:") ; System.out.println("Average = 29.85") ; System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ; System.out.println("EXPECTED:") ; System.out.println("Average of evens = 26.57") ; Random random = new Random(1) ; a = new int[100][1] ; for (int i = 0 ; i < 100 ; i++) a[i][0] = random.nextInt(1000) ; System.out.println("For an array of random values in range 0 to 999:") ; System.out.printf("Average = %.2f\n", average(a)) ; System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ; } /** Find the average of all elements of a two-dimensional array @param aa the two…arrow_forwardGiven the following: #includ int a[] ={4, 6}, i = 0, y =3, z =1; void f(int x){ int z = 2; g (); X = x + y; z = z +X; i++; return x + a[ i ]+y; } void g(){ z += 3; y = a[i] + z; } void main(){ printf("%d", y + f( a[i] ) - y); } State the output assuming the following: A) Call by reference, dynamic scoping, operands are evaluated right to left. B) Call by name, static scoping; operands are evaluated left to right.arrow_forward
- Create Test Suit for all test cases public class Arraymethod { public static void main(String[] args) { int [] array = {2,5,10,8,9,3}; System.out.println("Sum of array elements is:"+sum(array)); System.out.println("Average of array elements is:"+avg(array)); System.out.println("Maximum element of array is:"+max(array)); System.out.println("Minimum element of array is:"+min(array)); } //method for calculating sum of array elements public static int sum(int[] array) { int sum = 0; for(int i=0; i array[i]) { min = array[i]; } } return min; } } Create Test Suit for all test casesarrow_forwardpublic class Main { public static void main(String[] args) { //for 3rd question i have created a array int a[]={1,2,3,4,5}; Main m1=new Main(); System.out.println("OUTPUT:"); System.out.println("The value returned from Expert method by addition method is +Expert.add(10,20)); //for the 4th question System.out.print("The array elements are:"); for(int i=0;i5){ System.out.print("b is greater than 5"); } else{ System.out.print("b is lesser than or equal to 5"); } } class Expert{ //for 2nd question i have created a another method add returned a value to main method static int add(int a,int b){ return a+b; } }arrow_forwardpublic class FindArrayDifference { static void arrayDifference(int a[], int b[]) { int k = 0; int [] c = new int[a.length]; for(int i=0; i < a.length; i++) { int j; for(j = 0; j < b.length; j++) if(a[i] == b[j]) break; if(j == b.length) c[k++] = a[i]; } for(int j = 0; j < k; j++) System.out.println(c[j]); } public static void main(String[] args) { int a[] = {1,2,3,7,8,15,26}; int b[] = {1,2,3,15,4,8,6}; arrayDifference(a,b); } } Calculate the algorithm step number and algorithm time complexity of the above program?arrow_forward
- Analyze the following code:public class Test { public static void main(String[] args) { int[] x = {0, 1, 2, 3, 4, 5}; xMethod(x, 5); } public static void xMethod(int[] x, int length) { for (int i = 0; i < length; i++) System.out.print(" " + x[i]); }} The program displays 0 1 2 3 4 5 and then raises a runtime exception. The program displays 0 1 2 3 4 and then raises a runtime exception. The program displays 0 1 2 3 4. The program displays 0 1 2 3 4 5.arrow_forwardpublic class arrayOutput ( public static void main (String [] args) { final int NUM ELEMENTS = 3; int[] userVals = new int [NUM_ELEMENTS]; int i; } Type the program's output userVals [0] = 2; userVals [1] = 6; userVals [2] = 8; for (i = userVals.length - 1; i >= 0; −−1) { System.out.println(userVals [1]); } C.C. ? ? ??arrow_forwardimport java.util.Scanner; public class MorgansBonuses { public static void main(String[] args) { int WeeksWorked; int Reviews; int x, y; final int Quit = 99; double[][] bonuses = { { 5, 9, 16, 22, 30 }, { 10, 12, 18, 24, 36 }, { 20, 25, 32, 42, 55, 68 }, { 46, 54, 65, 77, 90 }, { 60, 72, 84, 96, 120 }, { 85, 100, 120, 140, 175 } }; Scanner ID = new Scanner(System.in); System.out.println("Please enter the number of weeks the employee has worked or " + Quit + " to quit.>>"); WeeksWorked = ID.nextInt(); while (WeeksWorked != Quit) { System.out.println("Please enter the number of positive reviews the employee has recieved or " + Quit +" to end program.>>"); Reviews = ID.nextInt(); if (WeeksWorked >= bonuses.length) { WeeksWorked = bonuses.length - 1; } if (Reviews >= bonuses[0].length) { Reviews =…arrow_forward
- Finish code with same class name and method namesarrow_forwardimport java.util.Scanner; public class Application {public static void main(String[] args){ int Num;float Ave;Employee[] Emp = new Employee[100]; System.out.println("Enter the number of employees:");Num = Integer.parseInt(new Scanner(System.in).nextLine());for (int i = 0; i < Num; i++){ Emp[i] = new Employee();Emp[i].Input();} System.out.printf("The list of employees:");System.out.println();Display(Emp, Num);Ave= AverageSalary(Emp, Num);System.out.printf("\nAverage salary is:" + "%.2f", Ave); System.out.printf("\nThe employee with highest salary is:\n" + employeeHigh(Emp, Num));}private static float AverageSalary(Employee [] emps, int n){float sum=0; for (int i = 0; i < n; i++)sum = sum + emps[i].salary;return sum/n;}private static void Display(Employee[] arr, int n){ for (int i = 0; i < n; i++){System.out.printf("%s",arr[i]);}}private static Employee employeeHigh(Employee[] arr, int n){ float high= arr[0].salary ;int iHigh = 0;for (int i = 1; i < n; i++){if( arr[i].salary…arrow_forwardIn C++ whats the answer from below ? int size = 10; for ( int i = -1; i < size ; i++) { arr[size - i] = i; } This array: has 12 positions is out of bounds has 10 positions has 11 positionsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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