can anyone tell my why this program bugs out when i enter more then 10 digits?
I wrote this program as an exercise, and although it appears to work fine, if I enter more then 10 digits it says illegal numeric format.
Can someone please tell me why it is doing this?
Code:
import acm.program.ConsoleProgram;
public class countdigits extends ConsoleProgram {
public void run () {
println ("this program counts the digits in a given number");
int x = readInt ("enter number:");
int y = 0;
println ("the number of digits in this number is: " + countInt(x, y));
}
public int countInt (int x, int y) {
int count = y;
while (x > 0) {
x /= 10;
count++;
}
return count;