0

When I try to return this way, the compiler throws an error.

Compile Message Main.java:15: error: missing return statement } ^ 1 error Exit Status 1

public class Main {
    static String distances(int x, int y, int z) {
        int distanceA = Math.abs(z-x);
        int distanceB = Math.abs(z-y);
        
        if(distanceB > distanceA) { 
            return "distance A";
        }
        else if(distanceB < distanceA) {
            return "distance B";
        }       
        else if(distanceB == distanceA) {
            return "distance C";
        }
    }
}

REST OF THE CODE.

Trushit Shekhda
  • 563
  • 7
  • 18
Nilesh
  • 3
  • 4

1 Answers1

0

turn the last else if 'else if(distanceB == distanceA)' into else and it should be work

aziz k'h
  • 775
  • 6
  • 11