Whats wrong in my code?

import java.util.Scanner;
public class INVERT {

public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	int n=input.nextInt();
	n=invert(n);
	reverse(n);
	}

public static int invert(int n) {
	int len=Integer.toString(n).length();
	int temp,a=0,c=0;
	while(a<len) {
		temp=n%10;
		n=n/10;
		if(temp>=5) temp=9-temp;
		c=c*10+temp;
		a++;
	}
	return(c);
}
public static void reverse(int n) {
	int len=Integer.toString(n).length();
	int temp,a=0,c=0;
	while(a<len) {
		temp=n%10;
		n=n/10;
		c=c*10+temp;
		a++;
	}
     System.out.println(c);
}

}

@KUNAL.SHARMA5724510 dry run your code for 332711047202 .also the constraints are for long int .
add the condition if their is 9 at the starting of the number then it must remain the same

PLEASE CORRECT MY CODE.

hi @KUNAL.SHARMA5724510
here is the correct code.
i have removed your reverse function because it will give wrong answer for n=999;
if you have any doubt feel free to ask :blush:
import java.util.Scanner;
public class INVERT {

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
long n=input.nextLong();
n=invert(n);
System.out.println(n);
}

public static long invert(long n) {
int len=Long.toString(n).length();
long temp,a=0,c=0, mul=1;
while(a<len) {
temp=n%10;
n=n/10;
if(n==0 && temp==9){
//do noting
}
else if(temp>=5)
temp=9-temp;

	c+=mul*temp;
	mul=mul*10;
	a++;
}
return(c);

}
public static void reverse(long n) {
int len=Long.toString(n).length();
long temp,a=0,c=0;
while(a<len) {
temp=n%10;
n=n/10;
c=c*10+temp;
a++;
}
System.out.println©;
}
}

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.