Groovy (function), 8179 bytes
Since initially submitting my answer, I've looked through some historic discussions here about what constitutes a suitable answer. Since it seems commonly accepted to provide just a method in Java (including return type and parameter declarations), here is a shorter, Groovy, method which has the method return value be the answer. Use of def
means that the return type is inferred.
def a(int n){n>0n?a(--n)+(n%3?'':'Yeah\n')+(n%2?'':'But\n')+(n%3==1?'No\n':''):''}
Unlike the original answer below, which loops from 0 up to n-1, this one calls itself from n down to 1, but decrements the input for the rest of the line in the recursive call.
[Try it online!][TIO-jlzjcese]jm1zjxcx]
Groovy (program), 87 bytes
Groovy scripts don't require certain common imports, so this can be a program printing the answer to Java's STDOUT without having to declare System.out.
before print
. It also provides some common utility methods, such as this toLong()
which allows us to parse the input argument reasonably consicely.
Essentially the Java 10 answer, but leveraging Groovy's shorter loop syntax and ability to evaluate truthy statements.
args[0].toLong().times{print((it%3?'':'Yeah\n')+(it%2?'':'But\n')+(it%3==1?'No\n':''))}
[Try it online!][TIO-jlzam5d2] [TIO-jlzjcese]jm1zjxcx]: https://tio.run/##Sy/Kzy@r/P8/JTVNIVEjM69EIU@zOs/OwD5RQ1c3T1NbI0/V2F5d3Uo9MjUxIyZPHSxiBBZxKi2BCRjb2hraq/vlA/lW6uqaQFz7vywJTVNIVEjM69EIU@zOs8@UUNXN09TWyNP1dheXd1KPTI1MSMmTx0sYgQWcSotgQkY29oa2qv75QP5VurqmkBcCzavJLW4RCNPU6GaSwEICoqApufkKSip5FkpIUSAtuZpoiqwBQElrlouLrAJBpoQ2hBKG8H4QImi1JLSorz/M0WhJLW4BGqqQjWXAhAUFAG5OXlKKnlWSggBoN15mijytiCgxFXLxQU2w0ATQhtCaSMYHyjBVZRaUlqU9x8AAA "Groovy – Try It Online" [TIO-jlzam5d2]: https://tio.run/##Sy/Kzy@r/P8/sSi9ONogVq8k3yc/L11DU68kMze1uLqgKDOvREMjs0TV2F5d3Uo9MjUxIyZPXVMbJGQEFnIqLYGLGNvaGtqr@@UDBazU1TU1a////29oAAA "Groovy – Try It Online"