3.1. Making Decisions
Making choices will be a fundamental element in all your programs. You need to be able to make decisions like, "If the user wants to enter more data, then read another value from the keyboard" or "If the bank balance is large, buy the car with the go-faster stripes, else renew the monthly bus ticket." Whatever decision you want to make, in programming terms it requires the ability to make comparisons between variables, constants, and the values of expressions and then execute one group of statements or another, depending on the result of a given comparison. Thus, the first step to understanding how you make decisions in a program is to look at how you make comparisons.
3.1.1. Making Comparisons
Java provides you with six relational operators for comparing two data values. The data values you are comparing can be variables, constants, or expressions with values drawn from Java's primitive data types—;byte, short, int, long, char, float or double.
Relational Operators | Description |
---|---|
> | Produces the value true if the left operand is greater than the right operand, and false otherwise. |
>= | Produces the value true if the left operand is greater than or equal to the right operand, and false otherwise. |
== | Produces the value true if the left operand is equal to the right operand, and false otherwise. |
!= | Produces the value true if the left operand is not equal to the right operand, and false otherwise. |
<= | Produces the value true if the left operand is less than or equal to the right ... |
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.