write a program that asks the user to input 2 values and find it's greatest common divisor,
اكتب برنامج يطلب من المستخدم يدخل قيمتين ويجد القاسم المشترك الأكبر لهما،
الحل:
كود PHP:
import java.util.*;
/
*
* @author deathpa1N
*/
public class GCD {
public static void main(String[] args) {
int counter=1,num1,num2,sum=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter the first number: ");
num1=input.nextInt();
System.out.println("Enter the second number: ");
num2=input.nextInt();
while (counter<=num1 && num1<num2 || counter<=num2 && num2<num1){
if (num1%counter==0 && num2%counter==0){
sum = counter;}
counter++;}
System.out.println("The greatest common divisor is: "+sum);