Question

1093-04 American Computer Sclence Lesg Intermediate DivisionーPRoa RAMMING Contest wa oni Back in the Saddle Agnin Problem A matrix is a 2 columns, and its called 3-by-2 matric A saddle point of a matrix is any value of the marix that in buth the largst vu in its d the largest value in its column·Thr are l-ndle polde the man hms kk in the last row of the matrix had been a 6, the matrix would have only one saddle polsd & the 4 in the last row had been an 8, the matrix would have ne saddlle pointa. Finally, M the ast row har been a s, the matrix would have the single saddle point. S. (Thin i-tricky!) Input: Five above. All matrices will be Output: Print the saddle must be listed in order to receive credit. If a saddle point appears more than once (as would happen t matricen. Fach matrix starta with the number of rows (r) and cakumne () of the by the r-by-e columns. The firet data line below correponds to the sample matri amaller than 6-by-6, and all values will be positive Integrs points of ench matrix. If the matrix has no saddle pointa, print a mege to that effect. If the matrix has more than one saddle point, they may be Visted in any order, a If the 8 were changed to a 5 in the example above), it must be listed only once Sample Input: Line #1: 3, 2, s, 2, 3, i. 4, 8 Line 2: 3, 3. 3, 2, 4, 1, 1, 6, 4, 2, 5 Line #3: 4, 2, 9, 3·5·8. 6, 32 1 Line#4: 4, 3, 1, 2, 3, 4, 2,4,6,8. 1, s. 5, 7 Line #5: 3, 2, 5, 2, 6, 8, 3-8 Sample Output: Output 1: 5 and 8 Output #2: 6 Output 3: 8 and 9 Output #4: 7 and 8 Output 5: none Please wsite the prora in Java us JOPhon Pane
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class SaddlePoint {


    private static String getSaddlePoint(int[][] array) {
        String output="";
        for (int cols = 0; cols < array[0].length; cols++) {
            int rowHigh = -1;
            int indexHigh = -1;
            for (int row = 0; row < array.length; row++) {
                if (array[row][cols] > rowHigh) {
                    rowHigh = array[row][cols];
                    indexHigh = row;
                }
            }

            boolean isColumnHighest = true;
            for (int k = 0; k < array[0].length; k++) {
                if (array[indexHigh][k] > rowHigh) {
                    isColumnHighest = false;
                }
            }
            if (isColumnHighest) {
                output+=rowHigh+", ";
            }
        }
        return output;
    }



    public static void main(String[] strings) {

        //3,2,5,2,3,1,4,8
        //3,3,3,2,4,1,1,6,4,2,5
        //4,2,9,3,5,8,6,3,2,1
        //4,3,1,2,3,4,2,4,6,8,1,3,5,7

        String sentence = JOptionPane.showInputDialog("Enter input");

        String[] splitStrings = sentence.split(",");
        int[][] matrixArr = new int[Integer.parseInt(splitStrings[0])][Integer.parseInt(splitStrings[1])];
        int counter = 2;
        for (int i = 0; i < matrixArr.length; i++) {
            for (int j = 0; j < matrixArr[0].length; j++) {
                matrixArr[i][j] = Integer.parseInt(splitStrings[counter++]);
            }
        }

        //System.out.println(Arrays.deepToString(matrixArr));

        JOptionPane.showMessageDialog(null, getSaddlePoint(matrixArr));

    }


}

////////////////Output////////

Test [-/IdeaProjects/Test] - .../src/SaddlePoint.java [Test] IntelliJ IDEA En 9:29 AM File Edit View Navigate Code Analyze ReMessage 令 (ⓢ4x 9:29 AM * File Edit View Navigate Code Analyze Refactor Build Run Iools VCs Window Help Test src) SaddlePoint

Add a comment
Know the answer?
Add Answer to:
1093-04 American Computer Sclence Lesg Intermediate DivisionーPRoa RAMMING Contest wa oni Back in the Saddle Agnin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT