猿问

最大公约数,运行错误,求解?!

import java.util.Scanner;

 

public class Main {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Scanner in = new Scanner(System.in);

        int a = in.nextInt();

        int b = in.nextInt();

        System.out.print(gongyue(a, b));

    }

 

    static int gongyue(int n, int m) {

        if (m <= n)

            if (n % m == 0)

                return (m);

            else

                return gongyue(m, n % m);

        else

            return gongyue(m, n);

    }

 

}


运行错误如下:

Exception in thread "main" java.util.InputMismatchException: For input string: "123456789101112"
at java.util.Scanner.nextInt(Scanner.java:2166)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Main.main(Main.java:8)

求改求解析!

LIN小黑
浏览 1069回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答