Largest row column in 5X5 matrix 8.10
- import java.util.Random;
- public class BinaryRow {
- public static void main(String[] args) {
- int i,j;
- int iSumR,iSumC,iRow,iColumn;
- int [][]iBucket = new int [5][5];
- Random run = new Random();
- iRow = iColumn = 0;
- for ( i=0 ; i<5 ; i++ )
- {
- iSumR = 0;
- for ( j=0 ;j<5 ; j++ )
- {
- iBucket[i][j] = run.nextInt(2);
- System.out.print(iBucket[i][j] + " ");
- iSumR = iSumR + iBucket[i][j];
- }
- if ( iSumR > iRow )
- iRow = iSumR;
- System.out.println();
- }
- System.out.println("The largest row index " + iRow);
- for ( j=0 ; j<5 ; j++ )
- {
- iSumC = 0;
- for ( i=0 ; i<5 ; i++ )
- iSumC = iSumC + iBucket[i][j];
- if ( iSumC > iColumn )
- iColumn = iSumC;
- }
- System.out.print("The largest column index " + iColumn);
- }
- }
use random to create a 5x5 matrix and find the largest row and column
留言
張貼留言