concept good combination in category java

appears as: good combinations, good combination
Modern Java in Action: Lambdas, streams, reactive and functional programming

This is an excerpt from Manning's book Modern Java in Action: Lambdas, streams, reactive and functional programming.

Filtering good combinations

Let’s assume someone provides you with the first two numbers of the triple: a and b. How do you know whether that will form a good combination? You need to test whether the square root of a * a + b * b is a whole number. This is expressed in Java as Math.sqrt(a*a + b*b) % 1 == 0. (Given a floating-point number, x, in Java its fractional part is obtained using x % 1.0, and whole numbers like 5.0 have zero fractional part.) Our code uses this idea in a filter operation (you’ll see how to use this later to form valid code):

Java 8 in Action: Lambdas, streams, and functional-style programming

This is an excerpt from Manning's book Java 8 in Action: Lambdas, streams, and functional-style programming.

Filtering good combinations

Let’s assume someone provides you with the first two numbers of the triple: a and b. How do you know whether that will form a good combination? You need to test whether the square root of a * a + b * b is an integer number; that is, it has no fractional part, which in Java can be expressed using expr % 1.0. If it’s not an integer, that means c is not an integer. You can express this requirement as a filter operation (you’ll see how to connect it later to form valid code):