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
Please make this java program work
Instruction: Write a test program that inputs, sorts, outputs Integer and Float. And call the isEqualTo method.
import java.util.*;
public class Generics <E>{ public static < E > void printArray( E inputArray[] ) { // Display array elements for( E element : inputArray) { System.out.printf("%s ", element); } System.out.println(); } public static < E extends Comparable<E> > void selectionSort(E array[]){ int size = array.length; for (int i = 0; i < size-1; i++){ // Find the minimum element int min = i; for (int j = i+1; j < size; j++) if (array[j].compareTo(array[min]) < 0) min = j; // Swap the found minimum element with the first element E temp = array[min]; array[min] = array[i]; array[i] = temp; } } public static <…
First, write a Java method isSequence that takes as parameters a non-empty 2-dimensional array of integers. The method checks whether the elements of the array are consecutive or not.Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output.Finally, use the following main method to test your different methods:public class CheckSequence{public static void main(String[] args){int[][] array1 = {{5,6,7,8},{9,10,11,12},{13,14,15,16}, {17,18,19,20}};int[][] array2 = {{1, 3 , 2,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};if (isSequence(array1)){System.out.println("The following array elements are successive:");printArray(array1);}if (isSequence(array2)){System.out.println("The following array elements are successive:");printArray(array2);}}}
Write the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.
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
- FOR JAVA Write a static method histogram() that takes an array a[ ] of int values and an integer M as arguments and returns an array of length M whose ith entry is the number of times the integer i appeared in the argument array. If the values in a[ ] are all between 0 and M–1, the sum of the values in the returned array should be equal to a.length.arrow_forwardUSING JAVA First, write a Java method isSequence that takes as parameters a non-empty 2-dimensional array of integers. The method checks whether the elements of the array are consecutive or not. Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output. Finally, use the following main method to test your different methods: public class CheckSequence { public static void main(String[] args) { int[][] array1 = {{5,6,7,8},{9,10,11,12},{13,14,15,16}, {17,18,19,20}}; int[][] array2 = {{1, 3 , 2,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; if (isSequence(array1)) { System.out.println("The following array elements are successive:"); printArray(array1); } if (isSequence(array2)) { System.out.println("The following array elements are successive:"); printArray(array2); } } } Run Example: The following array elements are successive: 56789 10 11 1213 14 15 16 17 18 19 20arrow_forwardWrite a Java method called average which takes an array as parameter and returns the average value. [1, 2, 3] 2 Create an array in main method, call the method and print it out. Troubleshooting: do you return a value in average method? class Main {public static double average(int [] array) {}public static void main(String[] args) {}}arrow_forward
- Write in JAVA, JUST CHANGE THE SWAP PART I don't want int i and j in (public static void swap(int[] array, int i, int j)) this part. DELETE I, AND J HERE. IT MUST BE JUST INT[] ARRAY I want you to do it by writing( public static void swap(int[] array){ Just initialize i and j somewhere else please. How can you do that? public class SelectionSort {public static void main(String[] args) {int[] intarray = {20, 35, -15, 7, 55, 1, -22};for(int lastUnsorted = intarray.length-1;lastUnsorted > 0;lastUnsorted--){// if largest is in 0th index// we start from the 1st index// if 1st is greater than it, swap the elementint largest=0;for(int i=1; i<=lastUnsorted; i++){if(intarray[i] > intarray[largest]){largest = i;}}swap(intarray, largest, lastUnsorted);}for(int i=0; i<intarray.length; i++){System.out.println(intarray[i]);}}public static void swap(int[] array, int i, int j){if(i == j){return;}int temp = array[i];array[i] = array[j];array[j] = temp;}}arrow_forwardUse the java code below and integrate additional method to: Print the minimum values of each row and of each column. public class ArrayOperations2D {public static int[] findRowMax(int[][] anArray) {int[] max = new int[anArray.length];for (int i = 0; i < anArray.length; i++) {int largest = anArray[i][0];for (int j = 0; j < anArray[i].length; j++) {if (anArray[i][j] > largest) {largest = anArray[i][j];}}max[i] = largest;}return max;}public static int[] findRowSums(int[][] anArray) {int[] rowSums = new int[anArray.length];for (int i = 0; i < anArray.length; i++) {int sum = 0;for (int j = 0; j < anArray[i].length; j++) {sum += anArray[i][j];}rowSums[i] = sum;}return rowSums;}public static int[] findColumnMax(int[][] anArray) {int[] max = new int[anArray[0].length];for (int j = 0; j < anArray[0].length; j++) {int largest = anArray[0][j];for (int i = 0; i < anArray.length; i++) {if (anArray[i][j] > largest) {largest = anArray[i][j];}}max[j] = largest;}return…arrow_forwardPlease help debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning public class DebugBox { private int width; private int length; private int height; private FixDebugBox() { length = 1; width = 1; height = 1; } public DebugBox(int width, int length, int height) { width = width; length = length; height = height; } public void showData() { System.out.println("Width: " + width + " Length: " + length + " Height: " + height); } public double getVolume() { double vol = length - width - height; return vol; } }arrow_forward
- Write in JAVA, JUST CHANGE THE SWAP PART I don't want int i and j in (public static void swap(int[] array, int i, int j)) this part. I want you to do it by writing( public static void swap(int[] array){ Just initialize i and j somewhere else please. How can you do that? public class SelectionSort {public static void main(String[] args) {int[] intarray = {20, 35, -15, 7, 55, 1, -22};for(int lastUnsorted = intarray.length-1;lastUnsorted > 0;lastUnsorted--){// if largest is in 0th index// we start from the 1st index// if 1st is greater than it, swap the elementint largest=0;for(int i=1; i<=lastUnsorted; i++){if(intarray[i] > intarray[largest]){largest = i;}}swap(intarray, largest, lastUnsorted);}for(int i=0; i<intarray.length; i++){System.out.println(intarray[i]);}}public static void swap(int[] array, int i, int j){if(i == j){return;}int temp = array[i];array[i] = array[j];array[j] = temp;}}arrow_forwardWrite a Java method that counts increasing sets in an integer array. The sets do not overlap. Example: 10,9,9,4,5 Output would be 3(10) (9,9) (4,5)arrow_forwardUse Java programming. Write the removeEvens() method, which receives an array of integers as a parameter and returns a new array of integers containing only the odd numbers from the original array. The main program outputs values of the returned array. Hint: If the original array has even numbers, then the new array will be smaller in length than the original array and should have no blank elements. Ex: If the array passed to the removeEvens() method is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the method returns and the program output is: [1, 3, 5, 7, 9] Ex: If the array passed to the removeEvens() method is [1, 9, 3], then the method returns and the program output is: [1, 9, 3] import java.util.Arrays; public class LabProgram { public static int[] removeEvens(int [] nums) { /* Type your code here */} public static void main(String[] args) { int [] input = {1,2,3,4,5,6,7,8,9};int [] result = removeEvens(input); // Helper method Arrays.toString() converts int[] to a…arrow_forward
- Write a Java program to find continuous sub array of the given array whose sum is equal to a given number. For example, If {12, 5, 31, 9, 21, 8} is the given array and 45 is the given number, then you have to find continuous sub array in this array such that whose elements add up to 45. In this case, {5, 31, 9} is such sub array whose elements add up to 45.arrow_forwardFOR JAVA, PLEASE WRITE THE CODE OF THIS QUESTION FOR JAVA Write a static method histogram() that takes an array a[ ] of int values and an integer M as arguments and returns an array of length M whose ith entry is the number of times the integer i appeared in the argument array. If the values in a[ ] are all between 0 and M–1, the sum of the values in the returned array should be equal to a.length.arrow_forwardFirst, write a Java method isSequence that takes as parameters a non-empty 2-dimensional array of integers. The method checks whether the elements of the array are consecutive or not.Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output.Finally, use the following main method to test your different methods: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