Java Scanner Usage computeSumTable(Scanner in, short n)

Here you can find the source of computeSumTable(Scanner in, short n)

Description

compute Sum Table

License

Open Source License

Declaration

public static int[][] computeSumTable(Scanner in, short n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Scanner;

public class Main {
    public static int[][] computeSumTable(Scanner in, short n) {
        int[][] matrix = new int[n][n];

        int xSum = 0;
        for (int x = 0; x < n; x++) {
            xSum += in.nextInt();/*from   w  w w  .j av a  2 s . c o m*/
            matrix[x][0] = xSum;
        }

        for (int y = 1; y < n; y++) {
            xSum = 0;
            for (int x = 0; x < n; x++) {
                xSum += in.nextInt();
                matrix[x][y] = xSum;
                matrix[x][y] += matrix[x][y - 1];
            }
        }

        return matrix;
    }
}

Related

  1. asList(String source, String separator)
  2. calcCompileWarnings(String compilerResult)
  3. cleanUpEmptyLinesAndIndent(String input)
  4. close()
  5. common(Scanner in)
  6. confirm(String message)
  7. confirm(String message)
  8. confirmAction(String warning)
  9. countFileLines(Scanner fin)