Chewbacca and Number in JAVA

My code compiled successfully and gave the correct result for all the testcases except 4th. What correction is required?

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
long n = scn.nextLong();
int length = (int)(Math.log10(n)+1);
int[] arr = new int[length];
int temp;
for(int i =length-1;i>=0;i–){
temp = (int)(n%10);
if(9-temp<temp && 9-temp!=0){
arr[i] = 9-temp;
}else{
arr[i] = temp;
}
n=n/10;
}
for(int i =0;i<length;i++){
System.out.print(arr[i]);
}
}
}

I got it.
I was not allowing 0 for any inverted number while it is not allowed for only the first digit.

Hey @Raunak-Agrawal-1537545869717573
Please mark your doubts as resolved in your course’s.