This program uses 3 random numbers to simulate 3
dice rolls. It repeats the dice rolls 10 times.
Each time the dice are rolled, the program must decide whether 2 of the dice
match (as shown in the results above).
if(a==b || b==c || a==c)
{ println( ....
"MATCH"); }
This command checks whether dice A matches dice B OR dice B
matches dice C OR dice C matches dice A.
The | | symbols stand for "OR". The = = symbol
checks whether two numbers are equal.
If a match is detected, then it prints "MATCH".
else
{ println(..... "no
match"); }
"Else" means "otherwise".
So if NO match occurs, it prints "no match".
George Boole was a mathematician who outlined the basic
principles of logical decisions.
A Boolean expression is
a series of logical operations that give a result of TRUE or
FALSE.
The basic operators in Boolean expressions are OR and AND.
For example, when a = 4 , b = 5 , c = 4, then
Whenever a Boolean expression uses OR ( | | ) , only one part
must be true to make the whole thing true.
The Java symbol for AND
is && . For
example, when a = 4, b = 5, c = 4 , then
AND expressions
(a == b && b == c ) ==> FALSE, because
both parts are false
(a == b && a == c ) ==> FALSE, because
a == b is false
(a == 4 && c == 4 ) ==> TRUE, because
both parts are true
The following command checks whether two numbers are smaller
than 100 and add up to 150.
( a < 100 && b < 100 && a+b==150 )
AND
&&
OR | | EQUAL
= = not Equal ! =
Less than or equal
< = Greater or
equal > =
You should find a summary of Boolean expressions in a Java
textbook and study all the possible operations.