public static int longestConsecutive(int[] num) {//passed after consulting
        Arrays.sort(num);
        for (int j = 0; j < num.length; ++j) {
            System.out.println(num[j]);
        }
        int len = 1;
        int templen = 1;
        int i = 1;
        while (i < num.length) {
            while (i < num.length && num[i] - num[i-1] == 1) {
                ++templen;
                ++i;
            }
            ++i;
            if (templen > len) {
                len = templen;
            }
            templen = 1;
        }
        return len;
    }