Largest row column in 5X5 matrix 8.10

  1. import java.util.Random;
  2. public class BinaryRow {
  3.  
  4.     public static void main(String[] args) {
  5.         int i,j;
  6.         int iSumR,iSumC,iRow,iColumn;
  7.         int [][]iBucket = new int [5][5];
  8.         Random run = new Random();
  9.         iRow = iColumn = 0;
  10.         for ( i=0 ; i<5 ; i++ )
  11.             {
  12.             iSumR = 0;
  13.             for ( j=0 ;j<5 ; j++ )
  14.                 {
  15.                 iBucket[i][j] = run.nextInt(2);
  16.                 System.out.print(iBucket[i][j] + " ");
  17.                 iSumR = iSumR + iBucket[i][j];
  18.                 }
  19.             if ( iSumR > iRow )
  20.                 iRow = iSumR;
  21.             System.out.println();
  22.             }
  23.         System.out.println("The largest row index " + iRow);
  24.     for ( j=0 ; j<5 ; j++ )
  25.         {
  26.         iSumC = 0;
  27.         for ( i=0 ; i<5 ; i++ )
  28.             iSumC = iSumC + iBucket[i][j];
  29.         if ( iSumC > iColumn ) 
  30.             iColumn = iSumC;
  31.         }
  32.     System.out.print("The largest column index " + iColumn);
  33.     } 
  34. }
use random to create a 5x5 matrix and find the largest row and column

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year