Simple java code
\n# Complexity\n- \n\n# Code\n\nclass Solution {\n    public String sumD(String s,int k){\n        int n=s.length();\n        String s2="";\n        for(int i=0
\n# Complexity\n- \n![image.png](https://assets.leetcode.com/users/images/9e7aaa48-a14d-4324-8efa-bda44002359d_1703989776.1976728.png)\n# Code\n```\nclass Solution {\n    public String sumD(String s,int k){\n        int n=s.length();\n        String s2="";\n        for(int i=0;i<n;i=i+k){\n            int sum=0;\n            int flag=0;\n            for(int j=i;j<i+k&&j<n;j++){\n                int key=(int)(s.charAt(j)-\'0\');\n                sum+=key;\n                flag=1;\n            }\n            if(flag==1){\n                s2=s2+sum;\n            }\n            else{\n                for(int j=i;j<n;j++){\n                    int key=(int)(s.charAt(j)-\'0\');\n                    sum+=key;\n                }\n                s2=s2+sum;\n                break;\n            }\n\n        }\n        return s2;\n    }\n    public String digitSum(String s, int k) {\n        if(s.length()<=k){\n            return s;\n        }\n        String s2=sumD(s,k);\n        while(s2.length()>k){\n            s2=sumD(s2,k);\n        }\n        return s2;\n    }\n}\n```
['Java']