Compiler says missing return statement but I already have 3

java

Solution

You have to make sure that there is always a value returned. If all your conditions fail you don't return anything.

A fix would be to chain your `if` statements because they are exclusive and use a `else` to catch all other cases.

public int tortoiseMoves() {
    int i = tGen();
    if (i >= 1 && i <= 5)
    {
        int fastplod = 3;
        return fastplod;
    }

    else if (i >= 6 && i <= 8)
    {
        int slowplod = 1;
        return slowplod;
    }

    else if (i >= 9 && i <= 10)
    {
        int slip = -6;
        return slip;
    }
    else {
        // return something or throw exception
        return 0;
    }
}

Problem

This is just weird. My compiler says I am missing a return statement, but I already have 3. Here is my code: ``` public int tortoiseMoves() { int i = tGen(); if (i >= 1 && i <= 5) { int fastplod = 3; return fastplod; } if (i >= 6 && i <= 8) { int slowplod = 1; return slowplod; } if (i >= 9 && i <= 10) { int slip = -6; return slip; } } ```

Original source