Getting run error

import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int d=0;
int[] arr=new int[18];
int k=0,c=0;
while(N>0){
int r=N%10;
d=(9-r);
if(d>r){
d=r;
}
arr[k]=d;
k++;
c++;
N=N/10;
}
if(arr[c-1]==0) {
System.out.print(9);
}else {
System.out.print(arr[c-1]);
}
for(int i=c-2;i>=0;i–){
System.out.print(arr[i]);
}
sc.close();
}
}

@Rajput.apry hi lemme check!

1 Like

@Rajput.apry hi priya the problem was the constraints, the range suits long rather than int, check em when you do problems, below you can find ya corrected code. I your query is resolved close ya doubt by marking it resolved and rate full else feel free to ask!

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
long N=sc.nextLong();//change3
int d=0;
int[] arr=new int[18];
int k=0,c=0;
while(N>0){
int r=(int)(N%10);//change2
d=(9-r);
if(d>r){
d=r;
}

		arr[k]=d;
		k++;
		c++;
		N=N/10;
    }
	if(arr[c-1]==0) {
    	System.out.print(9);
    }
	else {
    	System.out.print(arr[c-1]);
    }
    for(int i=c-2;i>=0;i--){
		System.out.print(arr[i]);
	}
}

}