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
public static void main(String[] args)
{
int a;
int b;
int c;
c = quad(0,1, 2);
b = quad(1, 2, 3);
a = quad(5, 6, 7);
c = c +b+ a;
}
private static int quad(int a, int b, int c)
{
int r;
r= a +b+ c;
return r;
}
For the code above, how many
entries does the activation record for method
quad have?
During the execution of main, at most how many
activation records are existent
on the run-time stack?
Complete this ap.
10.
public static void methodl (int i, int num) {
for (int j = 1; j <= i; j++) {
" ");
System.out.print (num +
num *= 2;
}
System.out.println();
}
public static void main(String[] args) {
int i = 1;
while (i <= 6) {
methodl (i, 2);
i++;
}
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
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (8th Edition)
In the circuit shown in Fig. P 7.26, both switches operate together; that is, they either open or close at the ...
Electric Circuits. (11th Edition)
Personal Information Class Design a class that holds the following personal data: name, address, age, and phone...
Starting Out with Python (4th Edition)
A harder version of Programming Project 4 would be to write a class named List, similar to Project 4, but with ...
Problem Solving with C++ (10th Edition)
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th 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
- Given 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_forwardCreate 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_forward
- public 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_forwardpublic class ReplaceEvenWithZero { public static void main(String[] args) { int[]a = new int[]{14, 2, 19, 3, 15, 22, 18, 7, 44, 39, 51, 78} ; // Print array a for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); // Replace the even elements. replaceEven(a); // Print array a again to see new elements. for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } /** Replace the even elements in the given array with 0 @param arr the array to use for the replacements */ public static void replaceEven(int[] arr) { //-----------Start below here. To do: approximate lines of code = 2 // Write a for loop to go through each element, determine if it is even //If so, replace with 0. Hint: use the modulus operator % to determine if an…arrow_forwardpublic static void simpleLoop(int total) { String tmp = ""; for (int x = 0; x < total; x++) { tmp + (x + ","); } } } System.out.println(tmp.length()); public static void main(String[] args) { simpleLoop (2);arrow_forward
- a) FindMinIterative public int FindMin(int[] arr) { int x = arr[0]; for(int i = 1; i < arr.Length; i++) { if(arr[i]< x) x = arr[i]; } return x; } b) FindMinRecursive public int FindMin(int[] arr, int length) { if(length == 1) return arr[0]; return Math.Min(arr[length - 1], Find(arr, length - 1)); } What is the Big-O for this functions. Could you explain the recurisive more in details ?arrow_forward1- class Excep { 2- public static void main(String[] args){ 3 try{ int arr[]=(1,2}; 4 int x = arr[1]/arr[0]-1; 6 7 catch(ArithmeticException e) 8- { 9. System.out.printin("divide by e"); 10 } 11 catch(ArrayIndexOutofBoundsException e) 12- { 13 System.out.println("wrong indexing"); 14 15 finally 16- { 17 System.out.println("Runtime error"); 18 } 19 }} 20 Answer:arrow_forwardpublic static void main(String[] args) { int[] funky = {1, -5, 3, -5, 6, 6, 6, 7, -5};int expectedFunkyRange = 5; // |6 - 1| = 5System.out.println("Expected funkyRange of " + Arrays.toString(funky) + " to be " + expectedFunkyRange + " and got " + funkyRange(funky));int[] funkyTwo = {6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1};int expectedFunkyRangeTwo = 4; // |4 - 8| = 4System.out.println("Expected funkyRange of " + Arrays.toString(funkyTwo) + " to be " + expectedFunkyRangeTwo + " and got " + funkyRange(funkyTwo)); Write a static method: public static int WeirdRange(int[] a) that that calculates the difference between the mode and "anti-mode" of an array of integers. This difference should be a positive number (you can use Math.abs to calculate an absolute value). If the array is empty or null, return -1. If the array has only one thing in it, return 0 (since the mode and anti-mode are the same). Definitions: The mode of an array is the element that occurs the most frequently.…arrow_forward
- Finish code with same class name and method namesarrow_forwardAnalyze the following code. 1. public class Test { 2. public static void main(String[] args) { 3. Fruit[] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)}; 4. java.util.Arrays.sort(fruits); 5. } 6.} class Fruit { private double weight; public Fruit(double weight) { this.weight = weight; } } The program has a compile error because the Fruit class does not have a no-arg constructor. The program has a runtime error on Line 3 because the Fruit class does not have a no-arg constructor. The program has a compile error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable. The program has a runtime error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.arrow_forward1. For each statement, circle the response that best completes it. For the first nine statements, consider this Java method and the array shown to its right. array public static int linkSum(int'a, int startLoc, int sunlimit) ( startLoc; int sun 0, 1 while (1>0 & sun sunlimit) { aun- sum + a[i]; 1 = a[i]; } return dum; (i) The expression linkSum (junk, 3, 12) evaluates to a. 13 b. 22 c. 10 d. 1 (ii) The call linkSum (junk, b. 4 a. 1 c. 5 (iii) The call linkSum (junk, Array IndexOutOfBoundsException a. 1 c. 5 0 1 2 3 4 5 6 7 Junk 1 0141711131-1101 211 startLoc d. 6 ,20) results in an infinite loop. e. none of above ,15) results in an being thrown. d. 6 e. none of above b. 2 (iv) In the method above (applied to any array), we can be sure that at the moment that the loop terminates. a. a[i] startLoc || sun >= sunlimit d. 1 = sumlinit c. 1 <0 & sum e. none of the above (v) In the method above, each of int and static is a(n) a reserved word b. variable c. expression (vi) In the method…arrow_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