Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

5-3 What are the current trends in computer hardware platforms?

Answered: 1 week ago