// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class TryAgain {
    public static String arr2strLast3(int[] a) {
        StringBuffer sb = new StringBuffer("");
        int last = -1;
        for (int i = 0; i < a.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            if ((a[i] / 1000) != last) {
                if(i > 0) {
                    sb.append("\r\n");
                }
                sb.append(a[i] / 1000);
                sb.append(",");
                last = a[i] / 1000;
            }
            sb.append(a[i] % 1000);
        }
        return sb.toString();
    }
    public static String arr2strFirst2(int[] a) {
        StringBuffer sb = new StringBuffer("");
        int last = -1;
        for (int i = 0; i < a.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            int n = 10;
            while(a[i] / n >= 100) n *= 10;
            if ((a[i] / n) != last) {
                if(i > 0) {
                    sb.append("\r\n");
                }
                sb.append(a[i] / n);
                sb.append(",");
                last = a[i] / n;
            }
            sb.append(a[i] % n);
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        int[] ia = { 5500, 5520, 55023, 11052 };
        System.out.println(arr2strLast3(ia));
        System.out.println(arr2strFirst2(ia));
    }
}
