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
Textbook Question
Chapter 8, Problem 8.2PE
(Sum the major diagonal in a matrix) Write a method that sums all the numbers in the major diagonal in an n × n matrix of double values using the following header:
public static double sumMajorDiagonal (double[][] m)
Write a test
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Average the major diagonal in a matrix) Write a method that averages all the numbers in the major diagonal in an n * n matrix of double values using the following header:
public static double averageMajorDiagonal(double[][] m)
Write a test program that reads a 4-by-4 matrix and displays the average of all its elements on the major diagonal. Here is a sample run:
1 2 3 4.0
5 6.5 7 8
9 10 11 12
13 14 15 16
Average of the elements in the major diagonal is 8.625
[Fish
Tank]
You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j.
When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that
is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving
right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly
m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size.
The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…
(Sort ArrayList)
Write the following method that sorts an ArrayList:
public static <E extends Comparable<E>> void sort(ArrayList<E> list)
Write a test program that prompts the user to enter 10 integers, invokes this method to sort the numbers, and displays the numbers in increasing order.
Sample Run
Enter 10 integers: 3 4 12 7 3 4 5 6 4 7
The sorted numbers are 3 3 4 4 4 5 6 7 7 12
Class Name: Exercise19_09
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
Convert the following code to an if-elif-else statement: if number == 1: print('One') else: if number == 2: pri...
Starting Out with Python (4th Edition)
What is a repetition structure?
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Write a Java statement to output the value in variable d of type double to the screen. The output should be in ...
Absolute Java (6th Edition)
Why do some standard SQL-92 statements fail to run successfully in Microsoft Access?
Database Concepts (7th Edition)
Write a function called b that takes two arguments: an u and a bit number n. Have the function return 1 bit num...
Programming in C
Write a program that determines the change to be dispensed from a vending machine. An item in the machine can c...
Java: An Introduction to Problem Solving and Programming (7th 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
- (Algebra: perfect square ) Write a program that prompts the user to enter an integer m and find the smallest integer n such that m * n is a perfect square. (Hint: Store all smallest factors of m into an array list. n is the product of the factors that appear an odd number of times in the array list. For example, consider m = 90, store the factors 2, 3, 3, 5 in an array list. 2 and 5 appear an odd number of times in the array list. So, n is 10.) Sample Run 1 Enter an integer m: 1500 The smallest number n for m x n to be a perfect square is 15 m x n is 22500 Sample Run 2 Enter an integer m: 63 The smallest number n for m x n to be a perfect square is 7 m x n is 441 Class Name: Exercise11_17 Answer is : import java.util.Scanner; public class Squares { public static void main(String[] args) { Scanner scan = new Scanner(System.in); //instantiation of Scanner that will take inputs from the keyboard //the try catch block below is for trapping error with the input try {…arrow_forwardi. Creates a matrix using: B=rand (20) a-write a program to find all numbers less than or equal 0.5 and put them in a new matrix with dimension 20x10. you can extend with zeros to fill the matrix. b- Do same as point a for all numbers above 0.5. c- Count all the numbers less or equal 0.3 , the numbers between 0.3 and 0.7 and count the numbers more than or equal 0.7.Put the results in a new vector with dimension 3x1. d- Replace the numbers of between 0.7 and 0.9 with 1. e- Add all the elements column wise.arrow_forward(Compute total marks for each student) Suppose the marks obtained by all students are stored ina two-dimensional array. Each row records a student’s marks for five tests. For example, the followingarray stores the test marks for eight students. Write a program that displays students and the totalmarks they obtained in five tests, in decreasing order of the total marks.arrow_forward
- Create a program for Matrix with the following requirements: 1. Allow the user to select what operation to perform like: finding eigenvalues and eigenvectors, sketching the Gershgorin circles, and diagonalization. 2. Allow the user to input any size of the matrices and their elements. 3. Display the matrix input and the result of the operation.arrow_forward(See attached photo) Please explain the exact running time of the program. The attached photo's answer is already correct only the explanation of getting the exact running time is needed.arrow_forward3-Write a test program that reads a n-by-m matrix Reads a real numbers and computes the sum and average.arrow_forward
- Please add comment and use Java Programming to solve this question! Thank you very much!!!! Write a method that sums all the numbers in the major diagonal in an n x n matrix of double values using the following header:public static double sumMajorDiagonal(double[][] m)Write a test program that first prompts the user to enter the dimension n of an n x n matrix, then asks them to enter the matrix row by row (with the elements separated by spaces). The program should then print out the sum of the major diagonal of the matrix.arrow_forward(FYI: Pseudocode is required (Not any programming language) Design a pseudocode program that loads an array with the following 7 values. Add one more word (of your own choosing) for a total of 8 words. biffcomelyfezmottleperukebedraggledquisling Be sure to use lowercase, as shown above. This will make the processing easier. Ask the user to enter a word Search through this array until you find a match with the word the user entered. Once you find a match, output "Yes, that word is in the dictionary". If you get to the end of the array and do NOT find a match, output "No, that word is not in the dictionary". The program should work with any set of words in the arrays. If I were to change the words in the arrays, it should still work. If you need help, look at the search example in your textbook.arrow_forwardTask 01: Assume P(x,y) is (x+y>4). Write a function/method that can validate the nested quantifier Vy P(x,y) for elements from two arrays X and Y. i. hint: The method returns l if statement is valid (the sum of all pairs of values from X and Y is greater than 4), and returns 0 otherwise. Valid case: For arrays X={2,3,4} and Y={3,4,5), the method returns 1(since xEX and býyEY, xi+y>4) Invalid case: For arrays X={2,3,4} and Y={1,4.5}, the method returns 0 (since 2EX and l EY but 2+1<4)arrow_forward
- Java Objective:Design and implement simple matrix manipulation techniques.Details:Your java program should use 2D arrays to implement simple matrix operations.Your program should do the following:• Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order• Print M1 to the console; make sure you format as a matirx• Repeat the previous steps for a second matrix M2• Create a matrix M3 that is the transpose of M1 and print it to the console• Check if M1 and M2 can be added (should have the same dimensions). If possible, add M1 and M2 and print the result to the console. Otherwise print an error message.• Multiply M1 and M2 if possible and print to the console. If the matrices cannot be multiplied, print an error message. Implementation requirements:• Use a helper method for reading a positive integer using an input validation loop.• Use a helper method for printing…arrow_forwardExercise 1: (Design of algorithm to find greatest common divisor) In mathematics, the greatest common divisor (gcd) of two or more integers is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4. Why? Divisors of 8 are 1, 2, 4, 8. Divisors of 12 are 1, 2, 4, 6, 12 Thus, the common divisors of 8 and 12 are 1, 2, 4. Out of these common divisors, the greatest one is 4. Therefore, the greatest common divisor (gcd) of 8 and 12 is 4. Write a programming code for a function FindGCD(m,n) that find the greatest common divisor. You can use any language of Java/C++/Python/Octave. Find GCD Algorithm: Step 1 Make an array to store common divisors of two integers m, n. Step 2 Check all the integers from 1 to minimun(m,n) whether they divide both m, n. If yes, add it to the array. Step 3 Return the maximum number in the array.arrow_forward(Two dice are rolled 100 times (you can do this with two random values from 1 to 6 in your program). After rounding 100 times, keep the iteration value of how many times each state occurs in a two-dimensional array. For example, the index number of [1,1] must follow the number of times the dice rolls 1 to 1).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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License