Groovy web console

subscribe to the feed Subscribe
to this
site

fac

Published 2 weeks ago by glenn
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
// example
int plus(a, b) {
    return a + b;
}
assert plus(2, 3) == 5;
System.out.println("result: " + plus(2, 3));

// Faculty
// Definition and task
// fac(1) = 1
// n > 1: fac(n) = n * fac(n-1)
// Please implement an algorithm that prints out the faculty for n = 1, 2, ... , 10
// Please don't use stream API, no input error handling needed
// Expected output: 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800