fork download
import java.util.*;
import java.lang.*;
import java.io.*;
 
class MatrixApp
{
   private static final int  X_INIT = -Integer.MAX_VALUE;
   
   public static Integer scanInteger( Scanner in )
   {
       return ( ( in.hasNextInt() ) ? in.nextInt() : null );
   }
 
   public static Double scanDouble( Scanner in )
   {
       return ( ( in.hasNextDouble() ) ? in.nextDouble() : null );
   }
   
   public static void main( String[] args )
   {       
      // проверка ввода порядка n
      Scanner in = new Scanner(System.in); 
      
      int n = scanInteger( in );
      
      if( n <= 0 )
      {
         System.out.printf("error: incomplete input of n\n");
         return;
      }
      
      if( n <= 1 )
      {
         System.out.printf("error: wrong value of n\n");
         return;
      }
      
      // создаем массив нужной размерности
      double arr[][] = new double[n][n];

      // ввод матрицы с проверкой
      for( int i = 0; i < n; i++ )
      {
          for( int j = 0; j < n; j++ )
         {
           arr[i][j] = scanDouble( in );
        }      
      }
      
      in.close();
      
      // печать введённой матрицы для отладки
      System.out.printf("input array:\n");
      for( int i = 0; i < n; i++ )
      {
         for( int j = 0; j < n; j++ )
         {
            System.out.printf("\t%2.2f", arr[i][j]);        
         } 
         System.out.printf("\n");   
      }

      // вывод результата, содержит номер строки, где необходимо было искать наибольший элемент
      System.out.printf("result:\n");
      for( int i = 0; i < n; i++ )
       {
         if( arr[i][i] < 0 )
         {
            double x = arr[i][0]; 
            for( int j = 1; j < n; j++ )
            {   
               if( arr[i][j] > x ) x = arr[i][j];             
            }
            System.out.printf("line = %d, max = %2.2f\n", i, x); 
          }  
       }
 
   
   }
}
Success #stdin #stdout 0.15s 321344KB
stdin
3
0 	1 	3
-2  -5  -1
-4  -9  -4
stdout
input array:
	0.00	1.00	3.00
	-2.00	-5.00	-1.00
	-4.00	-9.00	-4.00
result:
line = 1, max = -1.00
line = 2, max = -4.00