← Java from Scratch Lesson 12 of 88 · 10 XP

Boolean

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

boolean is true or false. It usually comes from a comparison:

int age = 17;
boolean adult = age >= 18;
System.out.println(adult);      // false — in lower case

In Java a boolean isn't a number: if (1) is a compile error, and an int doesn't turn into a boolean. Name them as questions: isAlive, hasKey, canJump.

Task. Read a year and print true if it's a leap year (divisible by 4 and not by 100, or divisible by 400), otherwise false. No if — one expression.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.