Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:16:43+00:00 2026-05-30T08:16:43+00:00

Im trying to get the min value in a column in the row of

  • 0

Im trying to get the min value in a column in the row of the max value. Im trying to using for loops but its not working.

Let say a matrix A:

3 4 5
2 3 4
1 2 3

I want the program to find the max value in the [0]th row then find the min value in the colunm of the max.
So result should be : max of row [0] = 5, min of column [2] = 3.
I then want it to do the same of all the rows, that why I ysed a while loop.

Here is the matrix:

public int[][] createMatrix(int a, int b){
    Scanner  inputm = new Scanner(System.in);
  A = new int[a][b];  
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++){
    System.out.println("Enter numbers for " + i +"th row");
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = inputm.nextInt();

    }

}
return A;
}

public int[][] displayMatrix(){
 System.out.println("Matrix A: ");

    for (int i=0 ; i < A.length ; i++)
    {     System.out.println();
        for  (int j=0 ; j < A[i].length ; j++){
            System.out.print(A[i][j]+" ");
              }
    }


return A;

}


public int getMaximumOfEveryRow (int c){ 
    a=c;
int i= 0;
int j;
 while(i < A[a].length){

    max = Integer.MIN_VALUE;
    for (  j = 0; j < A [ i ].length; j++ )
        if ( A [ i ] [ j ] > max ){
            max = A [ i ] [ j ];
        }



            for (  i = 0; i < A [ i ].length; i++ )// e
        if ( A [ i ] [ j ] < min ){
            min = A [ i ] [ j ];
        }

        System.out.println( "\n Maximum of row " + j + " = " + max );
    System.out.println( "Minimum of column " + i + " = " + min );        
    if(max == min){
    System.out.println( min+ " = " + max );
    System.out.println( "This is a saddle point. ");
    }




    i++;

 }     
return max;


}

and this is what I have so far:

public int getMaximumOfEveryRow (int c){ 
    a=c;
int i= 0;
int j;
 while(i < A[a].length){

    max = Integer.MIN_VALUE;
    for (  j = 0; j < A [ i ].length; j++ )
        if ( A [ i ] [ j ] > max ){
            max = A [ i ] [ j ];
        }


    int e = j;  
    int r;
            for (  i = 0; i < A [ i ].length; i++ )// e
        if ( A [ i ] [ j ] < min ){
            min = A [ i ] [ j ];
        }

        System.out.println( "\n Maximum of row " + j + " = " + max );
    System.out.println( "Minimum of column " + i + " = " + min );        
    if(max == min){
    System.out.println( min+ " = " + max );
    System.out.println( "This is a saddle point. ");
    }




    i++;

 }     
return max;


}
public int getMaximumOfEveryColumn ()
{
for ( int i = 0; i < A.length; i++ )
{
    maxc = Integer.MIN_VALUE;
    for ( int j = 0; j < A [ i ].length; j++ )
        if ( A [ j ] [ i ] > maxc )
            maxc = A [ j ] [ i ];
    System.out.println( "Maximum of column " + i + " = " + maxc );
}
return maxc;
}

public int getMinimumOfEveryColumn_(){
for ( int i = 0; i < A.length; i++ )
{
    minc = Integer.MAX_VALUE;
    for ( int j = 0; j < A [ i ].length; j++ )
        if ( A [ j ] [ i ] < minc )
            minc = A [ j ] [ i ];
    System.out.println( "Minimum of column " + i + " = " + minc );
}
return minc;
}
public int getMaximumOfEveryRow ()
{
for ( int i = 0; i < A.length; i++ )
{
    maxr = Integer.MIN_VALUE;
    for ( int j = 0; j < A [ i ].length; j++ )
        if ( A [ i ] [ j ] > maxr )
            maxr = A [ i ] [ j ];
    System.out.println( "Maximum of row " + i + " = " + maxr );
}
return maxr;
}

code for finding the max value in colunm and then finding the min value in the row of that max value.

public void get_max_of_the_row_of_local_min ()
{
 for ( int i = 0; i < A.length; i++ )
 {
    min = Integer.MAX_VALUE;
    max = Integer.MIN_VALUE;
    int index_of_min_in_its_col = 0;



    //maxc = Integer.MIN_VALUE;
    for ( int j = 0; j < A [ i ].length; j++ )

        if ( A [ j ] [ i ] > max ){
            max = A [ j ] [ i ];
            index_of_min_in_its_col = i;
            System.out.println( " Maximum of col [" + i + "] = " + max);
        }

   for ( int j = 0; j < A [ index_of_min_in_its_col ].length; j++ )

        if ( A [ index_of_min_in_its_col ] [ index_of_min_in_its_col ] < min ){
            min = A [ index_of_min_in_its_col ] [ index_of_min_in_its_col ];
   a =j;
        }
    //System.out.print( " Maximum of col [" + j + "] = " + max);
    System.out.println( " Minimum of rol [" + index_of_min_in_its_col + "] = " + min );

    if(max == min){
    System.out.println("This is a saddle point.");
    }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:16:45+00:00Added an answer on May 30, 2026 at 8:16 am

    Here is the solution:

    public void get_minimum_of_the_column_of_local_maximum ()
    {
        for ( int i = 0; i < A.length; i++ )
        {
            min = Integer.MAX_VALUE;
            max = Integer.MIN_VALUE;
            int index_of_maximum_in_its_row = 0;
    
            for ( int j = 0; j < A [ i ].length; j++ )
                if ( A [ i ] [ j ] > max )
                    {
                        max = A [ i ] [ j ];
                        index_of_maximum_in_its_row = j;
                    }
    
            for ( int j = 0; j < A [ index_of_maximum_in_its_row ].length; j++ )
                if ( A [ j ] [ index_of_maximum_in_its_row ] < min )
                    min = A [ j ] [ index_of_maximum_in_its_row ];
    
            System.out.print( " Maximum of row [" + i + "] = " + max);
            System.out.println( " Minimum of column [" + index_of_maximum_in_its_row + "] = " + min );
        }
    }
    

    What does this code snippet do?

    You have min = Integer.MAX_VALUE, max = Integer.MIN_VALUE variables. The reason we assign these values to this numbers is to make finding max/min possible. How? Initially min has the greatest integer value but as far as we find a value less than it we update our minimum so the min‘s value decreases. Same technique with max variable but of course it goes the other direction by increasing in value after comparisons.

    First inner for loop determines the maximum of row i, then marks the index of maximum in that row by using variable index_of_maximum_in_its_row. It is required to be used later on in the second inner loop.

    Second inner loop determines the minimum of column number index_of_maximum_in_its_row with one iteration over that column. Than the method prints the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I am trying to get a min date, a max date, and
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I've been trying to get a slider to display its current value next to
I am trying to fetch the minimum value of a column in MySQL using
Let's say I have a min and a max number. max can be anything,
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get Struts 2 and Tiles to work and I am using
Trying to get an ASP application deployed; it worked for a while but then
It is ok to set the max & min value for a UISlider control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.