我似乎無法找到解決這個錯誤..請不要判斷我。初學者在這裏。GCD,歐幾里德的算法
import java.util.Scanner;
public class GreatestCommonDivisor {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
int num1;
int num2;
int gcd;
boolean again = false;
do {
System.out.print("First positive integer: ");
num1 = inputPosInt();
System.out.print("Second positive integer: ");
num2 = inputPosInt();
//....
gcd = gcd();
(again) = tryAgain();
} while (again); {
System.out.println("Thank you for testing this program.");
}
}
public static int inputPosInt() {
Scanner kbd = new Scanner(System.in);
int num;
num = kbd.nextInt();
if (num < 0) {
System.out.println("Entered integer value is non-positive.");
return 0;
}
return num;
}
public static int gcd(int num1, int num2) {
if (num2==0) {
return num1;
}
return gcd(num2,num1%num2);
}
public static boolean tryAgain() {
Scanner kbd = new Scanner(System.in);
System.out.print("Would you like to try again? [Y/N]");
char again;
again = kbd.nextLine().charAt(0);
if (again == 'y' || again == 'Y') {
return true;
}
else if (again == 'n' || again == 'N') {
System.exit(0);
}
return false;
}
}
該程序需要2個正整數輸入,並使用歐幾里得算法求解其GCD。
錯誤: gcd = gcd(); ^ 要求:INT,INT 發現:沒有參數 原因:實際的和正式的參數列表長度 1個錯誤
您宣佈函數需要2個整數,並且您沒有將它稱爲它。 – Randy
信息的哪部分你不明白? – SLaks