mercredi 27 septembre 2017

Java error with else if statements

I get the error "Syntax error on token "else", delete this token" when trying to compile this. The goal is to take the median of the 3 numbers.

public class TestMedian {
    public static void main(String[] args) {
        System.out.println(median(7, 3, 9));        // 7
        System.out.println(median(29, -14, 11));    // 11
        System.out.println(median(752, 64, 121));   // 121
    }

    public static int median(int num1, int num2, int num3){
      int middle = (num1);
      if(num1 >= num2 && num1 <= num3 || num1 >= num2 && num1 >= num3);{
        System.out.println("The median is " + middle);
      } else {
        middle = (num2)
        System.out.println("The median is " + middle );
      }
      if (num2 >= num1 && num2 <= num3 || num2 <= num1 && num2 >= num3){

      }else{
        middle = (num3)
        System.out.println("The median is" + middle);
      }
    }

}

Aucun commentaire:

Enregistrer un commentaire