Your approach is close but for each iteration that produces zero for the mod you need to reflect that. You could use a String to track the result of each iteration and convert it to an integer for the return value like this:
public static int toBin(int Num) {
String result = "";
while (Num > 0) {
int mod = Num % 2;
result = mod + result;
Num /= 2;
}
return Integer.parseInt(result);
}
For example the method above if you input 12 then each iteration would build the string like this "0", "00", "100", "1100"