Chewbacca number

import java.util.*;
public class Main {
public static long solution(String str){
long result=0;
for(int i=0;i<str.length();i++){
long digit=str.charAt(i)-‘0’;
long num=9-digit;
if(num==9|| num==0){
digit=digit;
}
else if(num<digit){
digit=num;

		}
		else{
			digit=digit;
			
		}
		
		result=result*10L+digit;
	}
	return result;
}	

public static void main(String args[]) {
   Scanner sc=new Scanner(System.in);
	//long x=sc.nextLong();
    String str;
	str=sc.next();
	System.out.println(solution(str));

}

}

whats wrong with my code one TC is getting failed

@niharikareddykeesara_139be65b4266e2f2 for input : 99999
Correct output : 90000
Your output : 99999. So debug your code for this.

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.

i have doubt regarding the input u have provided y we r having the digit 9 as 9 and remaining digits as 0 .if first digit is 9 y other digits cant be 9

i may not know i u give reply to my question its better if u send me the mail just like ur feedback

sir i have debugged the code but i was having the above doubt y expect i=0,remaining all the digits are zeroes