/*** * DTU, d. 23.10.01 * Course 02199, week 8, exercise 23 * Author: Nikolaj Hjelm Jensen, c971701@student.dtu.dk * Translated by: Cecilie, d. 10.09.02 * ***/ public class ArrayUtils { public static String arrayToString(int[] a) { String str = "[ "; for(int i = 0; i < a.length; i++) { str += a[i]+" "; } str += "]"; return str; } public static String arrayToString2(int[] a) { String str = "["+a[0]; for(int i = 1; i < a.length; i++) { str +=","+a[i]; } str += "]"; return str; } public static int occurences(int[] a, int n) { int occ = 0; for(int i = 0; i < a.length; i++) { if(a[i]==n) occ++; } return occ; } public static int sum(int[] a) { int sum = 0; for(int i = 0; i< a.length; i++) { sum += a[i]; } return sum; } }