'Coding in DART: Use a while loop to count the number of digits in a user inputed number
I have been asked to write a program that uses a while loop to count the number of digits in a user inputed number. I have been watching tutorials and reading every doc I've come across and everything I have tried hasn't worked. I can make it work by converting it to a string and using .length but I have to write it with a while loop. I don't get any error messages, and with all the variations I've tried I just get an infinite printing of 0 or what looks like an infinite counting up. Where am I going wrong with this?
int num = int.tryParse(stdin.readLineSync());
int digit = 0;
while (num > 0) {
digit +1;
num / 10;
print(digit);
}```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|