JAVA 8.1

  1. import java.util.Scanner;
  2. public class sumrow {
  3.  
  4.     public static void main(String[] args) {
  5.         int i,j;
  6.         Scanner input = new Scanner(System.in);
  7.         double[][] dBucket = new double[4][5];
  8.         for ( i=0 ; i<3 ; i++ )
  9.             for ( j=0 ; j<4 ; j++ )
  10.                 dBucket[i][j] = input.nextDouble();
  11.         for ( i=0 ; i<3 ; i++ )
  12.             System.out.println("sum of elements of row " + i + " result " + sumRow(dBucket,i));
  13.     }
  14.     public static double sumRow(double[][] m, int rowIndex )
  15.     {
  16.     double dSum;
  17.     dSum = 0.0;
  18.     for (int j=0 ; j<4 ; j++ )
  19.         dSum = dSum + m[rowIndex][j];
  20.     return dSum;   
  21.     }
  22. }

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year