Whats wrong with this code's logic?

3 test cases are passed but still 2 are failing…

import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
long answer = 0,var = 1;

	while(x!=0){
		long digit = x%10 ; 
		if(digit >= 5){
			if(digit == 9 && x/10 ==0){
				continue;
			}
			else
				digit = 9-digit;
		}

		answer = answer + digit*var ; 
		var*=10;
		x/=10;
	}
	System.out.println(answer);
}

}

hi @himanshuep32

import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
long answer = 0,var = 1;

while(x!=0){
	long digit = x%10 ; 
	if(digit >= 5){
		if(digit == 9 && x/10 ==0){
			//do nothing here if you continue from here then your answer will not be updated
		}
		else
			digit = 9-digit;
	}

	answer = answer + digit*var ; 
	var*=10;
	x/=10;
}
System.out.println(answer);

}
}

@himanshuep32
please mark your doubt as resolved and rate me aswell.

hey @himanshuep32 can you share your remaining doubt with me?