+ 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
9 Réponses
+ 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.
+ 1
I'll give you a hint: Your code basically ends in this loop:
while( n != 0 )
{
n = 9% 10;
}
+ 1
Martin Taylor no, I wanted to print each digit of the number (5378) seperately from left to right like
5
3
7
8
+ 1
Thanks Alex I get your point and resloved it.
+ 1
Oh sorry Coding Santa idk how I overlooked it. I corrected it now, thank you for helping me 😊
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?
0
Coding Santa it's still not working :(
0
Sneka R ?
- 1
No