Chewbacca and number1

I not get the question, pls help

You have to convert the given number x, into the minimum possible number. For every digit in x, you can replace x by 9-x. So, for minimum number, check if inverting digit is less than or greater than the original digit. If it is less, then invert it otherwise leave it.

And you have to check that the first digit should not become zero.

For example : 139263 is given. I will not invert first digit 1 as 9-1 is 8, which is larger. Same for 2nd, 4th and 6th digit. But I will replace 3rd and 5th digits as they would become (9-9 = 0) and (9-6=3). Thus the final number would become 130233

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn =new Scanner(System.in);

	System.out.println("size?");
    int n=scn.nextInt();
	 int[] arr=new int[n];
	 for(int i=0;i<arr.length;i++)
	 {
		 arr[i]=scn.nextInt();
	 }
	 for(int i=0;i<arr.length;i++)
	 {
		 if(arr[i]>9-arr[i])
		 {
			 arr[i]=9-arr[i];
            
		 }
		  
	 }

for(int i=0;i<arr.length;i++)
{ System.out.print(arr[i]);
}
}

}
its not working

In the question, the input is not given in the form of an array, it is given in the form of a number. So if you want to use an array you can take input in form of a string and convert it into an array. And you also need to check that if the first digit is 9, it should not be converted to zero otherwise it will reduce number of digits.

And remove this statement

If you have no further queries about this question, please mark your doubt as resolved

I not get the prev suggestion u give, should I first go through string topic then solve this problem

Yes you can do that. But that has nothing to do with what I suggested. What I meant was that the input is given as a number. Like 12345. So you cannot take input in the form of an array. Initially your code asks for size of array then takes n elements as input but that will not work here because the input given is a single number.

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.