Java
Code
# Code
```java []
class Solution {
    public int minMaxDifference(int num) {
       char c[] = String.valueOf(num).toCharArray();

		// assignoing first non 9 number to 9
		String big = "";
		String small = "";
		int ans = 0;
		int count = 0;
		char num1 = '0';
		for (int i = 0; i <= c.length - 1; i++) {

			if (c[i] != '9' && count == 0) {
				num1 = c[i];
				c[i] = '9';
				count++;
				big += 9;

			} else {
				if (count > 0) {
					if (c[i] == num1) {
						c[i] = '9';
						big += 9;
					} else {
						big += c[i];
					}
				}
				else {
					big += 9;
				}
			}
		}
		//System.out.println(big);
		// Making smallest number
		count = 0;
		num1 = '0';
		c = String.valueOf(num).toCharArray();
		for (int i = 0; i <= c.length - 1; i++) {

			if (c[i] != '0' && count == 0) {
				num1 = c[i];
				c[i] = '0';
				count++;
				small += 0;

			} else {
				if (count > 0) {
					if (c[i] == num1) {
						c[i] = '0';
						small += 0;
					} else {
						small += c[i];
					}
				}
				else {
					small += 0;
				}
			}
		}
		//System.out.println(small);
		ans = Integer.valueOf(big) - Integer.valueOf(small);
        return ans;
    }
}
```
['Java']