Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 156

Numeric Comparison Operators

Оглавление

The first four relational operators in Table 2.8 apply only to numeric values. If the two numeric operands are not of the same data type, the smaller one is promoted, as previously discussed.

Let's look at examples of these operators in action:

int gibbonNumFeet = 2, wolfNumFeet = 4, ostrichNumFeet = 2; System.out.println(gibbonNumFeet < wolfNumFeet); // true System.out.println(gibbonNumFeet <= wolfNumFeet); // true System.out.println(gibbonNumFeet >= ostrichNumFeet); // true System.out.println(gibbonNumFeet > ostrichNumFeet); // false

Notice that the last example outputs false, because although gibbonNumFeet and ostrichNumFeet have the same value, gibbonNumFeet is not strictly greater than ostrichNumFeet.

OCP Oracle Certified Professional Java SE 17 Developer Study Guide

Подняться наверх