+ 1

I wrote a java code to display each digit of a given number from left to right, I am getting timed out error, please help me

https://code.sololearn.com/cRGfJuTqplDo 1st while loop: to find out the number of digits(say, x). In this line,i=(10^(i-1)); I am making a number with (x-1) digits and 1 at left most and storing it in i. 2nd while loop: printing each digit of the number from left to right and reducing the number by one digit each time(by removing the left-most digit, of course). Please help me, I am unable to get my code into working https://code.sololearn.com/cRGfJuTqplDo/?ref=app

9th Dec 2021, 7:43 PM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
11 Respostas
+ 2
ThanksMartin Taylor ,yes I did the same mistake of confusing it to a math problem. The answer is really helpful, thanks again for sharing.
10th Dec 2021, 10:27 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
I'll give you a hint: Your code basically ends in this loop: while( n != 0 ) { n = 9% 10; }
9th Dec 2021, 8:41 PM
Alex
Alex - avatar
+ 1
Martin Taylor no, I wanted to print each digit of the number (5378) seperately from left to right like 5 3 7 8
10th Dec 2021, 7:07 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
Thanks Alex I get your point and resloved it.
10th Dec 2021, 8:19 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
Oh sorry Coding Santa idk how I overlooked it. I corrected it now, thank you for helping me 😊
10th Dec 2021, 8:20 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
0
Thanks Alex , Coding Santa but I have put i/=10; in while loop thereby reducing the equation to n = 9%1 in the next iteration, so I will get n = 0 as a result and then the loop should end?
10th Dec 2021, 7:06 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
0
Coding Santa it's still not working :(
10th Dec 2021, 8:08 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
11th Dec 2021, 5:48 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
- 1
No
11th Dec 2021, 5:46 AM
Sneka R