Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

American Computer Science League Contest #2 1993-94 Intermediate Division PROGRA

ID: 3783154 • Letter: A

Question

American Computer Science League Contest #2 1993-94 Intermediate Division PROGRAMMING "Back in the Saddle Again" Problem: A matrix is a rectangular arrangement of nu The matrix below has 3 rows and 2 columns, and it's called a 3-by-2 matrix: A saddle point of a matrix is any value of the matrix that is both the largest value in its row and the largest value in its column. There are two saddle points in the matrix above: 5 and 8. If the 4 in the last row of the matrix had been a 5, the matrix would have only one saddle point: 8. If the 4 in the last row had been an 8, the matrix would have no saddle points. Finally, if the 8 in the last row has been a 5, the matrix would have the single saddle point, 5. is is tricky!) Input: Five matrices. Each matrix starts with the number of rows (r) and columns (c) of the matrix, followed by the r-by-c columns. The first data line below corresponds to the sample matrix above. All matrices will be smaller than 6-by-6, and all values will be positive integers. Output: Print the saddle points of each matrix. If the matrix has no saddle points, print a message to that effect. If the matrix has more than one saddle point, they may be listed in any order; all must be listed in order to receive credit. If a saddle point appears more than once (as would happen if the 8 were changed to a 5 in the example above), it must be listed only once. Sample Input: Line #1: 3, 2, 5. 2, 3, 1, 4, 8 Line #2: 3, 3, 3, 2, 4, 1. 1. 6, 4, 2, 5 Line #3: 4, 2, 9. 3, 5, 8, 6, 3 2 1 Line #4: 4, 3, 1, 2, 3, 4. 2. 4, 6, 8, 1. 3, 5. 7 Line #5: 3, 2, 5, 2, 6. 8, 3, 8 Sample output: output #it 5 and 8 output #2: 6 output #3: 8 and 9 output #4: 7 and 8 output #5: none

Explanation / Answer

import java.util.Scanner; import javax.swing.JOptionPane; public class A2 { public static void main(String[] args) { double height=Double.parseDouble(JOptionPane.showInputDialog("Enter 1st side of triangle: ")); double base=Double.parseDouble(JOptionPane.showInputDialog("Enter 2nd side of triangle: ")); RightTriangle newTriangle = new RightTriangle(height, base); newTriangle.getHypotenuse(); double hypotenuse = newTriangle.getHypotenuse(); JOptionPane.showMessageDialog(null,hypotenuse); } public double height; public double base; public final double hypotenuse = Math.sqrt(Math.pow(height, 2) + Math.pow(base, 2)); public A2(double triHeight, double triBase) { height = triHeight; base = triBase; } public double getHypotenuse() { return hypotenuse; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote