Skip to main content
2 of 4
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/

#Java 7, 49 bytes

corsiKa's answer is exclusive, mine is inclusive (and slightly shorter by using recursion instead of a loop).

int q(int a,int b){return a+1!=b?a*q(a+1,b):a*b;}

Ungolfed & test code:

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println(q(2, 5));
        System.out.println(q(5, 10));
        System.out.println(q(-4, 3));
        System.out.println(q(0, 3));
        System.out.println(q(-4, -1));
    }

    static int q(int a, int b){
        return a+1 != b
            ? a * q(a+1, b)
            : a * b;
    }
}

Output:

120
151200
0
0
24
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384