code throws the following error: method greatestCommonDivisor in class Fraction cannot be applied to given types; and then follows with
required: int,int found: no arguments reason: actual and formal argument lists differ in length
I am not so sure why the error is there, I tried changing a few things with no luck
class Fraction{
private int numerator;
private int denominator;
public Fraction(int _num1, int _num2){
numerator = _num1;
denominator = _num2;
}
public int greatestCommonDivisor(int num1, int num2){
int greatestCommon = 1;
for(int i = 1; i <= num1 && i <= num2; i++){
if(num1 % i == 0 && num2 % i == 0)
greatestCommon = i;}
return greatestCommon;
}
}
public class testing2
{
public static void main(String[] arg)
{
Scanner in = new Scanner(System.in);
int num11 = in.nextInt();
int num22 = in.nextInt();
Fraction gcd = new Fraction(num11, num22);
System.out.println(gcd.greatestCommonDivisor());
}
}
greatestCommonDivisorexpects twointparameters, you are sending none. - Guy