Chewbacca and number test cases failed

import java.util.*;
public class Main {
public static void main(String args[]) {

Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
int mul=1;
int rnum=0;
while(num!=0)
{ int rev;
int rem=num%10;
if(num/10==0)
{

		if(rem==9 || rem<=4)
		{
			rev=rem;
		}
		else
		{
			rev=9-rem;
		}
	}
	else
	{
	if(rem<=4)
	{
		rev=rem;
	}
	else 
	{
		rev=9-rem;
	}
	
   
	}
	 rnum=rnum+rev*mul;
	    mul=mul*10;
	    num=num/10;
	
 }
System.out.print(rnum);
}

}

Your logic is completely correct, but if you check the constraint, it is that x can go up to 10^18. So using int here will not work. You will have to use ‘long’ datatype. Make that change and your test cases will pass.