import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int s = countDigit(n), arr[] = new int[s], num = 0;
for(int i = 0;i<arr.length;i++){
arr[arr.length-1-i] = n % 10;
n /= 10;
}
int i = 0;
if(arr[i] == 9){
i++;
}
for(;i<arr.length;i++){
int t = arr[i];
if(9-t<t){
arr[i] = 9 -t;
}
}
for(int k = 0;k<arr.length;k++){
long fact =1;
for (int j=1;j<=k; j++)
{
fact = fact * 10;
}
num =num + ( arr[arr.length-k-1] *(int) fact) ;
}
System.out.print(num);
}
public static int countDigit(int a){
int count = 0;
while(a>0){
count++;
a /= 10;
}
return count;
}
}=====what’s error in the code
Problem chewbacca and number
values can be larger so try the long
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.
yes my code is not working right can u please make the code right because i m stuck
pls share cb ide link of ur code