201111621308:
class Max
{
public static void main(String[] args){
Max a = new Max();
a.go();
}
}
void go(){
int a = 12 , b = 8 , c ;
}
完善后的程序:
package gdou.lcf.arithmetic;
import java.util.Scanner;
public class gcd {
public static void main(String[] args) {
System.out.println("please input two number:");
Scanner scanner = new Scanner(System.in);
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int gcdNum = getGCD(num1, num2);
System.out.println("the gcd is: "+gcdNum);
}
public static int getGCD(int num1, int num2){
//判断num1和num2的大小,将较大值赋给num1
if(num1 < num2){
int tmp = num1;
num1 = num2;
num2 = tmp;
}
//计算最大公约数
while(num1 % num2 != 0){
int tmp = num2;
num2 = num1 % num2;
num1 = tmp;
}
return num2;
}
}