Wrong answer in test case 3 and 5

Sir, My code gives the correct output but for testcase 3 and 5 it gives the wrong answer: please help:
Here is my code:
import java.util.;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
int i;
long s=0;
long number;
for(i=0;n%10!=0 || n/10!=0;n/=10,i++) {
number=n%10;
if(9-number>number)
s=(long) (s+(number
Math.pow(10, i)));
else
s=(long) (s+((9-number)*Math.pow(10, i)));
}
System.out.println(s);
sc.close();

}

}

Hi there is just extra condition that if the number starts with 9 then that 9 must not be replaced with 0.
For example if number is 9898 then the answer should be 9101 not 101. here is the corrected code

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.