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

Do I have everything I need for this? It is Java and I need to put it into two f

ID: 3789196 • Letter: D

Question

Do I have everything I need for this? It is Java and I need to put it into two files. What do I put where? Code Below

import java.util.*;
public class GCDLCM// this is GCDLCM class

{
   // gcd method
   public static int gcd(int x, int y){
       if(x<=1||y<=1)
           return 1;
       while(x!=y){
           if(x<y)
               y=y-x;
           else
               x=x-y;
       }
       return x;
   }
   // finding lcm method
   static int lcm(int x, int y)
{
int greater;
greater = (x > y) ? x : y; // greater number
while(true)
{
if(greater % x == 0 && greater % y == 0)
return greater;
++greater;
}  
}
  
   public static void main(String args[])// main method starts here
   {
       Scanner scan = new Scanner(System.in);
      
       System.out.println("GCD : "+gcd(180,81));
       System.out.println("LCM : "+lcm(180,81));
       System.out.println("GCD : "+gcd(7622,618));
       System.out.println("LCM : "+lcm(7622,618));
       System.out.println("GCD : "+gcd(4368,2653));
       System.out.println("LCM : "+lcm(4368,2653));
      
   }
     
}

Read the text Chapters 1 and 2 through section 2.7. For this assignment, create two claases, AssignGCD and GCD in separate source files. Place both source files in a package named for your last name In GCD, provide the following method Compute the greatest common divisor of the passed integers. *@param xan integer greater than 1 @para m an integer greater than 1 @return the G.C.D ofx and y, or 1 ifx or y IX ess than or equal to 1 public int gcd int y) return 1. while (x y) if (x

Explanation / Answer

Here are both the files. create a package with your lastname and then put both the files into it.

GCD.java

package simple;

public class GCD {

   // gcd method

   public int gcd(int x, int y)

   {

   if(x<=1||y<=1)

   return 1;

   while(x!=y){

   if(x<y)

   y=y-x;

   else

   x=x-y;

   }

   return x;

   }

   // finding lcm method

   public int lcm(int x, int y)

       {

           int greater;

           greater = (x > y) ? x : y; // greater number

           while(true)

           {

           if(greater % x == 0 && greater % y == 0)

           return greater;

           ++greater;

           }

       }

}

AssignGCD.java

package simple;

public class AssignGCD {

   public static void main(String[] args) {

      

       GCD gcd_lcm = new GCD();

     

       System.out.println("GCD(180,81)="+gcd_lcm.gcd(180,81));

   System.out.println("LCM(180,81)="+gcd_lcm.lcm(180,81));

   System.out.println("GCD(7622,618)="+gcd_lcm.gcd(7622,618));

   System.out.println("LCM(7622,618)="+gcd_lcm.lcm(7622,618));

   System.out.println("GCD(4368,2653)="+gcd_lcm.gcd(4368,2653));

   System.out.println("LCM(4368,2653)="+gcd_lcm.lcm(4368,2653));

   }

}

OUTPUT:

GCD(180,81)=9

LCM(180,81)=1620

GCD(7622,618)=206

LCM(7622,618)=22866

GCD(4368,2653)=7

LCM(4368,2653)=1655472

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote