Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop the algorithm/pseudocode for the following specification. Also, remember

ID: 3769139 • Letter: D

Question

Develop the algorithm/pseudocode for the following specification. Also, remember to include a list of all your constants and variables. The greatest common factor (or greatest common divisor) of two integers is the largest integer that divides both numbers Write a program that inputs two numbers (in any order) and implements the following approach to finding their greatest common factor As sample input, the user enters 252 and 7531 The first step is to determine the remainder of the larger number (753) divided by the smaller number (252): 753/252 has a remainder of 231 Then, calculate the remainder of the old divisor (252) divided by the remainder found in the previous step (231). 252 / 231 has a remainder of 21 Continue this process until the remainder is zero 231/21 has a remainder of 0 The last divisor (21) is the greatest common factor

Explanation / Answer

import java.util.Scanner;


public class Test {
public static void gcd(int n1,int n2){
   while(n1!=n2)
{
if(n1>n2)
n1-=n2;
else
n2-=n1;
}
   System.out.println("Greatest Common Factor is: "+n1);
  
}
   public static void main(String args[]){
       int firstNumber,secondNumber;
       Scanner sc=new Scanner(System.in);
       System.out.println("Please Enter first Number");
       firstNumber=sc.nextInt();
       System.out.println("Please Enter Second Number");
       secondNumber=sc.nextInt();
       gcd(firstNumber,secondNumber);

   }
}