java
\nclass Solution {\n    public long smallestNumber(long num) {\n        if(num == 0L){return 0L;}\n        char[] arr = Long.toString(num).toCharArray();\n     
```\nclass Solution {\n    public long smallestNumber(long num) {\n        if(num == 0L){return 0L;}\n        char[] arr = Long.toString(num).toCharArray();\n        if(num > 0){\n            Arrays.sort(arr);\n            int i = 0;\n            while(arr[i] == \'0\'){\n                i ++;\n            }\n            char temp = arr[0];\n            arr[0] = arr[i];\n            arr[i] = temp;\n\n            StringBuffer sb = new StringBuffer();\n            for(char c : arr){\n                sb.append(c);\n            }\n            return Long.parseLong(sb.toString());\n        }else{\n            Character[] arr2 = new Character[arr.length-1];\n            for (int i = 0; i < arr.length-1; i++) {\n                arr2[i] = arr[i+1];\n            }\n           \n            \n            Arrays.sort(arr2, Collections.reverseOrder());\n            StringBuffer sb = new StringBuffer();\n            for(char c : arr2){\n                sb.append(c);\n            }\n            return Long.parseLong(sb.toString()) * -1L;\n        }\n        \n        \n    }\n}\n```
['Java']