Answered step by step
Verified Expert Solution
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
- 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 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 - 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started