Not completely clear about how to handle zeros. Do I have to completely ignore all 0's from output? 2 test cases working Only

What is the result of 2991? Is it 12 or 1002?
What is the result of 999? Is it 0?

Code:

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long n = 0;
if(sc.hasNextLong())
n = sc.nextLong();

    chewbacca(n);
}

public static void chewbacca(long n) {

    int arr[] = new int[10];

    int count = 0; //for all zeroes
    while(n > 0) {
         
        int r = (int) (n % 10);
        count++;
        if(r >= 5)
            r = 9 - r;
        arr[r]++;
        n = n / 10;
    }

    if(arr[0] == count) //all 0s
        System.out.print(0); 
    
    else {
        
    StringBuilder sb = new StringBuilder();

    for(int i = 1; i <= 9; i++) {
        while(arr[i] > 0) {
            sb.append(i);
            arr[i]--;
        }
    }

    System.out.print(sb);
    }
    
}

}

Hi ,
for 2991 ans should be 2001 and for 999 it is 900.You don’t have to change the length of the number.

Hi @Navneet01
as you are not responding to the doubt I am marking your doubt as resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.