Here you can find the source of checkSum(boolean[] a)
public static long checkSum(boolean[] a)
//package com.java2s; /*/*w ww .j a v a 2 s.co m*/ * Copyright (C) 2016 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static long checkSum(boolean[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (a[j] ? j + 1 : 0); } return sum; } public static long checkSum(boolean[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(long[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static long checkSum(long[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(int[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static long checkSum(int[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(short[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (short) (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static long checkSum(short[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(char[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (char) (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static long checkSum(char[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(byte[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += (byte) (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static long checkSum(byte[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static double checkSum(double[] a) { double sum = 0; for (int j = 0; j < a.length; j++) { sum += (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static double checkSum(double[][] a) { double sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static double checkSum(float[] a) { double sum = 0; for (int j = 0; j < a.length; j++) { sum += (a[j] / (j + 1) + a[j] % (j + 1)); } return sum; } public static double checkSum(float[][] a) { double sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(Object[][] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]); } return sum; } public static long checkSum(Object[] a) { long sum = 0; for (int j = 0; j < a.length; j++) { sum += checkSum(a[j]) * Math.pow(2, j); } return sum; } public static long checkSum(Object a) { if (a == null) return 0L; return (long) a.getClass().getCanonicalName().length(); } }