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);
}
}在第3行中,我将00486设为值,但根据我在Java中的知识,它显示的整数太大,允许的整数值要大得多。
发布于 2022-01-10 20:08:12
当您在数字前面添加0时,它将以八进制格式处理。在八进制格式中,允许的数字仅从0到7不等。因此,您需要将数字从00486更改为00476。但是要小心,这个数字将被转换成基本的10格式。为了验证这一点,我编写了一份打印语句,显示该数字将以基数10格式存储。
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);
}}
https://stackoverflow.com/questions/70658181
复制相似问题