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]);
}
}
}