Skip to content

Yes/no methods

Read · 1 of 2

Return true or false

static boolean isPrime(int n) answers a question. Then if (isPrime(n)) reads almost like a sentence.

A method stops as soon as it hits return, so you can return early: if (n < 2) return false;.