Java Solution with simple explanation.
Code \n\n\nclass Solution {\n    public String convertToBase7(int num) {\n        if (num == 0) return "0";\n        StringBuilder sb = new StringBuilder();\n  
## Code \n\n```\nclass Solution {\n    public String convertToBase7(int num) {\n        if (num == 0) return "0";\n        StringBuilder sb = new StringBuilder();\n        boolean isNegative = num < 0;\n        if (isNegative) num = -num;\n        while (num > 0) {\n            sb.append(num % 7);\n            num /= 7;\n        }\n        if (isNegative) sb.append("-");\n        return sb.reverse().toString();       \n    }\n}\n```\n\n## Explanation\n\n1. If num is 0, return "0".\n2. Initialize a StringBuilder object sb.\n3. Initialize a boolean isNegative to false.\n4. If num is negative, set isNegative to true and set num to -num.\n5. While num is greater than 0, append num % 7 to sb.\n6. If isNegative is true, append "-" to sb.\n7. Reverse the string in sb and return it.
['Java']