The operator is undefined for the argument type (s) Fraction, Fraction

1

A line of code (16) is giving me error where it tells me: The operator > is undefined for the argument type(s) Fraction, Fraction why can this happen? my code is:

public class RekursionKlassen {
    public static void main(String[] args) {
        Fraction[] arr={(new Fraction(2,2)),(new Fraction(3,3)),(new Fraction(4,4)),(new Fraction(5,5)),(new Fraction(6,6)) };
        int i = 4;
        System.out.print(maximum(arr,i));
    }
    public static Fraction maximum(Fraction[]arr,int i) {
        if( i<0 || i >=arr.length) {
            throw new RuntimeException(); 
        }
        else {
            if( i == 0) {
                return arr[0];
            } else {
                if(arr[i] > maximum(arr,i-1)) { //aqui me sale el error
                    return arr[i];
                }else {
                    return maximum(arr,i-1);
                }
            }
        }   
    }
}
    
asked by Kevin Zerull 02.12.2018 в 22:00
source

1 answer

1

Using maxFraction you can get the value of the largest fraction by comparing two fractions.

Replace

if(arr[i] > maximum(arr,i-1)) { //aqui me sale el error
                        return arr[i];
                    }else {
                        return maximum(arr,i-1);
                    }

By

Fraction res = maxFraction(arr[i], maximum(arr,i-1));
return res;

You can see more info here .

    
answered by 02.12.2018 / 22:27
source