import java.util.IntSummaryStatistics;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class TwoDimensionalArrayStream {
  private static int i = 0;
  public static void main(String[] args) {
    int[][] m = {{1, 2}, {3, 4}, {4, 5}, {1, 3}};
    
    int[] list = Stream.of(m).map(e -> IntStream.of(e)).
      reduce((e1, e2) -> IntStream.concat(e1, e2)).get().toArray();
    
    IntSummaryStatistics stats = 
      IntStream.of(list).summaryStatistics();
    System.out.println("Maksimum: " + stats.getMax());
    System.out.println("Minimum: " + stats.getMin());
    System.out.println("Suma: " + stats.getSum());
    System.out.println("Średnia: " + stats.getAverage());
    
    System.out.println("Sumy wierszy ");
    Stream.of(m).mapToInt(e -> IntStream.of(e).sum()).
      forEach(e -> 
        System.out.println("Suma wiersza nr " + i++ + ": " + e));
  }
}

