整数太大.错误,我该怎么办

发布于 2025-01-09 07:39:23 字数 344 浏览 3 评论 0原文

我正在做一个返回两个长数的 GCD 的函数,当我尝试这个示例时,我收到此错误“整数太大”,尽管我尝试使用的数字太多小于长值的最大值

public class MyClass {
    public static void main(String args[]) {
      System.out.println(reduction(149361408, 37822859361));
    }
    static long reduction(long a, long b){
        if(b==0) return a;
        return reduction(b, a%b);
    }
}

I am doing a function that return the GCD of two long number, and when I tried this example I get this error "integer number too large" although I tried with too number less than the max of long value

public class MyClass {
    public static void main(String args[]) {
      System.out.println(reduction(149361408, 37822859361));
    }
    static long reduction(long a, long b){
        if(b==0) return a;
        return reduction(b, a%b);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

打小就很酷 2025-01-16 07:39:23

在数字中添加“L”,表示它是长整型

public class MyClass {
    public static void main(String args[]) {
      System.out.println(reduction(149361408, 37822859361L));
    }
    static long reduction(long a, long b){
        if(b==0) return a;
        return reduction(b, a%b);
    }
}

Add an "L" to the number so you indicate is a Long

public class MyClass {
    public static void main(String args[]) {
      System.out.println(reduction(149361408, 37822859361L));
    }
    static long reduction(long a, long b){
        if(b==0) return a;
        return reduction(b, a%b);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文