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
Question
Chapter 8, Problem 8.25PE
Program Plan Intro
Markov matrix
Program Plan:
- Include the package “java.util.Scanner” into program.
- Define the class named “Exercise08_25”.
- Define the main method.
- Define the scanner object “obj” to get input from user.
- Declare and initialize a final variable “N” in type of integer.
- Prompt the user and declare the two dimensional variable “arr” in type of “double”.
- Using “for” loops, get input values for array “arr[][]”.
- Call the method “isMarkovMatrix()” which pass the “arr” as argument in “if” condition.
- Print appropriate statement on screen.
- Define the “isMarkovMatrix()” Boolean method which pass two dimensional array “m[][]” as argument.
- Using “for” loops and “if” condition, check the value of “m[][]” is less than “0”.
- If the condition is true, return “false”.
- Using “for” loop, add column values of matrix and return “true” if the value of “tot” equal to “1”. Otherwise return “false” to calling function.
- Using “for” loops and “if” condition, check the value of “m[][]” is less than “0”.
- Define the main method.
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
(Data Structures and Algo C++ Weiss 4th ed - ch7.40):
The following divide-and-conquer algorithm is proposed for finding the simultaneous maximum and minimum: If there is one item, it is the maximum and minimum, and if there are two items, then compare them, and in one comparison you can find the maximum and minimum. Otherwise, split the input into two halves, divided as evenly as possibly (if N is odd, one of the two halves will have one more element than the other). Recursively find the maximum and minimum of each half, and then in two additional comparisons produce the maximum and minimum for the entire problem.
In C++, find a function which will take in a vector and solve the problem, producing a vector of two elements, the min and max.
Assignment (Math application):Write a program that prompts the user to enter a 3 x 3 matrix of double values and testswhether it is a positive Markov matrix. An n x n matrix is a positive Markov matrix if the following is true:o If each of the elements is positiveo The sum of the elements in each column is 1
Sample Program running
Enter a 3 x 3 matrix by row0.15 0.875 0.3750.55 0.005 0.2250.30 0.12 0.4The sum of the columns1.0 1.0 1.0It is a Markov matrix
Enter a 3 x 3 matrix by row-0.2 0.875 0.3750.75 0.005 0.2250.45 0.12 0.4The sum of the columns1.0 1.0 1.0It is not a Markov matrix
Please note the following requirements:
Include a comment before each method explaining what the methods will do
All methods called from the main methods
There will be two methods which will be called from the main method:public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles2. Prompts the user for values as shown in the sample run3. Stores the numbers in the…
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...
Knowledge Booster
Similar questions
- [In C language] The concept of a "drunkard's walk" involves an individual who starts walking aimlessly from a lamp post. With each step they take, they move randomly either north, south, east, or west, each with a 25% probability. As the individual takes more steps, they tend to forget where they started and continue taking random steps. The objective is to determine how far the individual will be from the starting point (0,0) after taking N number of steps. To simulate this random walking motion for N steps, we can create a computer program. This program should ask the user to input an integer representing the number of steps to be taken. It should work for any positive value of steps, even for a large number. However, if the user enters an invalid number (such as a negative value), the program should display an error message. After each step, the program should show the current location of the random walker with respect to the origin (lamp post). Finally, when the random…arrow_forward3-Write a test program that reads a n-by-m matrix Reads a real numbers and computes the sum and average.arrow_forwardPlease convert Mutual Recursion to Java. See attached image. Thank you.arrow_forward
- CodeW For fun X C Solved https://codeworkou... 臺亂 CodeWorkout X272: Recursion Programming Exercise: Is Reverse For function isReverse, write the two missing base case conditions. Given two strings, this function returns true if the two strings are identical, but are in reverse order. Otherwise it returns false. For example, if the inputs are "tac" and "cat", then the function should return true. Examples: isReverse("tac", "cat") -> true Your Answer: 1 public boolean isReverse(String s1, String s2) { 2. if > 3. 4. else if > return true; return false; 5. 6. else { String s1first = String s2last return s1first.equals (s2last) && 51. substring(0, 1); s2, substring(s2.length() 1); 7. 8. 6. isReverse(s1.substring(1), s2.substring(0, s2.length() 1)); { 12} 1:11AM 50°F Clear 12/4/2021arrow_forwardالوقت للحل الى 6:00 مساءا اليومarrow_forwardNOTE: The algorithm should be written in pseudo code, (explanation of the algorithm rather than code)arrow_forward
- Exercise 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_forwardNeed help in python. Problem: 2D random walk. A two dimensional random walk simulates the behavior of a particle moving in a grid of points. At each step, the random walker moves north, south, east, or west with probability 1/4, independently of previous moves. Compose a program that takes a command-line argument n and estimates how long it will take a random walker to hit the boundary of a 2n+1-by-2n+1 square centered at the starting point. //Given codeImport stdioImport randomImport sysn = int(sys.argv[1])//write code herestdio.write('The walker took ')stdio.write(c)stdio.writeln(' steps')arrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science. Ridbit begins with an integer n. In one action, he can perform one of the accompanying tasks: partition n by one of its appropriate divisors, or take away 1 from n in case n is more prominent than 1. An appropriate divisor is a divisor of a number, barring itself. For instance, 1, 2, 4, 5, and 10 are appropriate divisors of 20, however 20 itself isn't. What is the base number of moves Ridbit is needed to make to decrease n to 1? Input The principal line contains a solitary integer t (1≤t≤1000) — the number of experiments. The main line of each experiment contains a solitary integer n (1≤n≤109). Output For each experiment, output the base number of moves needed to lessen n to 1.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_forwardPython quesarrow_forward(Kruskal’s algorithm) The text introduced Prim’s algorithm for finding a minimum spanning tree. Kruskal’s algorithm is another well-known algorithm for finding a minimum spanning tree. The algorithm repeatedly finds a minimumweight edge and adds it to the tree if it does not cause a cycle. The process ends when all vertices are in the tree. Design and implement an algorithm for finding an MST using Kruskal’s algorithm.This is a java code questionarrow_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