计算最大公约数_java编程答案
package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter first integer :"); int number1=input.nextInt(); System.out.print("Enter second integer :"); int number2=input.nextInt(); int Remainder=-1; int Max=-1; do{ Remainder=number1%number2; number1=number2; number2=Remainder; Max=Remainder; }while(number1%number2!=0); System.out.println("The greatest common divisor is "+Max); }}
页:
[1]