Question: Create a java program named EvaluateGCFAlgorithm.java Test and evaluate each algorithm Create a text file in the same folder (save it as results.txt) or provide

  1. Create a java program named EvaluateGCFAlgorithm.java
  2. Test and evaluate each algorithm
  3. Create a text file in the same folder (save it as results.txt) or provide data in the program, and summarize the times for each testing as shown in the following table.
    a, b gcf1 gcf2 gcf3
    2, 6 555555 55555 55555
    200, 1 999999 55555 55555
  4. Post data from your results.txt in the discussion board, and write down what you have learned from this practice in terms of program efficiency.

public class GCFAlgorithm {

public static int gcf1(int a, int b) {

if(Math.abs(a)==Math.abs(b))

return Math.abs(a);

if(a*b==0) return Math.abs(a+b);

return gcf1(a %b, b%a);

}

public static int gcf2(int a, int b) {

a=Math.abs(a);

b=Math.abs(b);

int tmp=a;

if(a==b)

return a;

if(a * b==0)

return a+b;

while(a*b !=0) {

tmp=a;

a =a %b;

b = b % tmp;

}

return a+b;

}

public static int gcf3(int a, int b) {

a=Math.abs(a);

b=Math.abs(b);

int tmp=a;

if(a==b)

return a;

if(a * b==0)

return a+b;

while(a*b !=0) {

if(a>b) a=a-b;

else b=b-a;

}

return a+b;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!