View Code of Problem 101

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.next().replace(",", "");
            StringBuilder res = new StringBuilder(str);
            int count = 1;
            if (res.length() == 4) {
                res.insert(1, ",");
            }else{
                for (int i = res.length()-1; i >0 ; i--) {
                    if (count == 3) {
                        res.insert(i, ",");
                        count=1;
                    }else{
                        count++;
                    }
                }
            }
            System.out.println(res);

        }
    }
}

Double click to view unformatted code.


Back to problem 101