like in case of 99 then do we need to print 1 or the number (99 ) only
What if the answer after inverting the digits is 0
the most probable error in this question is a corner case where all the digits are 9, or first digit is 9.(solution: first 9 should be untouched)
check your code for following examples:(left side is input, right side is expected output)
- 999 ----> 900
- 987 -----> 912
- 9 -------> 9
- 99 -------> 90
thanks
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.
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 sum=0,multiplier=1; while(n>0){ int ld = n%10; n/=10; if(ld>4){ ld=9-ld; } else if(n==0 && ld==9) ld=9; sum+=ldmultiplier; multiplier*=10; } System.out.println(sum); } }
Hi @Vishu_1801,
Your code is giving wrong output … for a test case say 9999 the output should be 1000 but your code is giving 1111… Please correct this and further errors.
And please save your code on ide.codingblocks.com as this code is very hard to understand … There is a ldmultiplier in the code what is that … check the code you posted
switch the if and else if part… if(n==0 && ld==9) should come before that ld>4 part.
thanks
Thanks for that but still test cases 3 and 4 are not covered they are showing a run error
the input can be large, take long long instead of int data type.
thanks
Still the test cases 3 and 4 are not covered
Did that as well but still unable to cover test case 3 and 4