Java
\nclass Solution {\n    public String digitSum(String s, int k) {\n        while (s.length() > k) {\n            int groups = s.length() / k + (s.length() % k =
```\nclass Solution {\n    public String digitSum(String s, int k) {\n        while (s.length() > k) {\n            int groups = s.length() / k + (s.length() % k == 0 ? 0 : 1);\n            \n            StringBuilder sb = new StringBuilder();\n            \n            for (int i = 0; i < groups; i++) {\n                int sum = 0;\n                \n                int size = i == groups - 1 ? s.length() - i * k : k;\n                \n                for (int j = 0; j < size; j++) {\n                    sum += s.charAt(i * k + j) - \'0\';   \n                }\n                \n                sb.append(sum);\n            }\n            \n            s = sb.toString();\n        }\n        \n        return s;\n    }\n}\n```
['String', 'Java']