Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 175
Verifying That the if Statement Evaluates to a Boolean Expression
ОглавлениеAnother common way the exam may try to lead you astray is by providing code where the boolean
expression inside the if
statement is not actually a boolean
expression. For example, take a look at the following lines of code:
int hourOfDay = 1; if(hourOfDay) { // DOES NOT COMPILE … }
This statement may be valid in some other programming and scripting languages, but not in Java, where 0
and 1
are not considered boolean
values.