Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
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?
public class Test {
}
public static void main(String[] args) {
String str = "Salom";
System.out.println(str.indexOf('t));
}
2. 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]);
}
}
a. The program displays 0 1 2 3 4.
b. The program displays 0 1 2 3 4 and then raises a runtime exception.
c. The program displays 0 1 2 3 4 5.
d. The program displays 0 1 2 3 4 5 and then raises a runtime exception.
e. There is a syntax error in the declaration of xMethod
Chapter 8 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
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_forwardpublic class Test { } public static void main(String[] args) { int arr[] = {1,2,3,4,5}; int count = 0; for(int i = } = 0; i<5; i++ ) { if(arr[i]%2==0) arr[i] *= 2; System.out.print(arr[i]); }arrow_forward10. 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++; }arrow_forward
- import 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_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }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
- 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_forward1- public class Con{ public static void main(String[] args) int[] ar=(2,5,7,9}; int i=2; final int j=1; 6. for (int x:ar) 8- { 9 if(ar[i]arrow_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_forwardCode: public class RURottenTomatoes { public static void main (String[] args) { int r = Integer.parseInt(args[0]); int c = Integer.parseInt(args[1]); for ( int i = 0; i < args.length; i++ ) { int[][] array = new int[r][c]; } String input = args[0]; int n = input.length(); String temp; int arrayR = r; int arrayC = c; for ( int i = 0; i < r; i++ ) { temp = input.substring( i, i + 1 ); arrayR = arrayR + Integer.parseInt(temp); for ( i = 0; i < c; c++ ) { temp = input.substring( i + 1, i + 2 ); arrayC = arrayC + Integer.parseInt(temp); } } } } I did all this, but then stuck. I have no idea what to do next, and I think my code is wrong. Can you help me out doing this assignment? Please explain everything that you do clearly! The instructions are below: RU Rotten Tomatoes. Write program RURottenTomatoes.java that creates a 2 dimensional integer array of movie ratings from the command line arguments and displays the index of the movie that has the highest sum of ratings.…arrow_forwardclass Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}} What will the given code prints on the output screen.arrow_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