Java 计算公约数和最大公约数

package java_1;

import java.util.Scanner;

public class Exercises_3{
	public static void main(String[] args) {
		
		Scanner input = new Scanner (System.in);
		
		try {
			
			int i=input.nextInt();
			int j=input.nextInt();
			int x;
			int a;
			int max=0;
			if(i>j) x=i;
			else    x=j;
			System.out.print("common divisor numbers : \n");	
			for(a=2;amax)
					max=a;                 //把a的值赋给max
				}
				
			}
			System.out.print("\nthe greatest common divisor is "+ max);	
		}
		finally {
			input.close(); //close the input
		}
	}
}

 

你可能感兴趣的:(java)