1
public class linklist {
    public static void main(String[] args) {
        int a = 00486;
        int x=zero(a);
        System.out.println(x);
    }
    public static int zero(int n)
    {
        if(n<=10)
        {
            return 0;
        }
        if(n%10==0) {
            return 1 + zero(n / 10);
        }
        else
            return zero(n/10);
    }
}

in line 3 i set 00486 as value but its showing integer too large error.As per my knowledge In Java, the integer value permissible is much bigger.

  • Does this answer your question? [Why is 09 "too large" of an integer number?](https://stackoverflow.com/questions/6935345/why-is-09-too-large-of-an-integer-number) – kirjosieppo Jan 12 '22 at 20:37

1 Answers1

0

When you add 0 in front of the number, it is treated in the octal format. In octal format, the allowed digits vary from 0 to 7 only . Therefore, you need to change the number from 00486 to 00476. But be beware, this number will be converted to base 10 format. To verify that, I have written a print statement that shows that the number will be stored indeed in base 10 format.

public class linklist {
public static void main(String[] args) {
    
    int  a = 0476;
    System.out.println(8*8*4 + 8*7 + 6);
    System.out.println(a);
    int x=zero(a);
    System.out.println(x);
}
public static int zero(double n)
{
    if(n<=10)
    {
        return 0;
    }
    if(n%10==0) {
        return 1 + zero(n / 10);
    }
    else
        return zero(n/10);
}

}

Gurkirat Singh Guliani
  • 1,009
  • 1
  • 4
  • 19