我是初学者,这是给学校的。请帮帮我,它必须是一个非常简单的程序,用户输入两个数字,结果是两个数字,一个 hcf 和一个 gcd。我分别编写了代码,但我不知道如何组合它们。
问问题
229 次
1 回答
2
转到您的 GCD 程序并获取计算 GCD 的代码并将其移动到函数中:
public int GCD(int a, int b) {
//find GCD
//return GCD
}
对 HCF 做同样的事情:
public int HCF(int a, int b) {
//find HCF
//return HCF
}
然后在main方法中:
//all the code for prompting the user for input
//and all the code for asking the user for input
//code which you've already written if you wrote these two programs independently already
System.out.println("GCD of " + input1 + " and " + input2 + " is " + gcd(input1, input2));
System.out.println("HCF of " + input1 + " and " + input2 + " is " + hcf(input1, input2));
于 2013-10-28T04:00:35.633 回答