Java Reference
In-Depth Information
relational Operators
Relational operators are usually binary operators. They check the relationship between two oper-
ands that are usually numbers or at least can be represented as numbers. They typically return a
Boolean value. Consider the following variables:
int a=4;
int b=9;
int c=4;
Table 2-13 illustrates the relational operators that can be used in Java.
tableĀ 2-13: Relational Operators
rel ational oper ator
meaning
ex amples
result
Greater than: Verifies whether operand 1 is strictly
bigger than operand 2.
False
>
a > b
Greater than or equals: Verifies whether operand
1 is strictly bigger than or equal to operand 2.
True
>=
b > a
Less than: Verifies whether operand 1 is strictly
lesser than operand 2.
True
<
c < b
Less than or equals: Verifies whether operand 1 is
strictly lesser than or equal to operand 2.
False
<=
b < a
Equal: Verifies whether operand 1 is equal to
operand 2.
True
==
a == c
Not equal: Verifies whether operand 1 is not equal
to operand 2.
True
!=
a != b
arrays
An array is a composite variable holding a fixed amount of values of a specific type (such as int ,
long , char , float , double , and so on). When an array is declared, the data type it will contain is
set. When it is initialized, the number of elements must be set as well. An array has a fixed number
of elements that are accessed by an index, which points to the n th element of the array. It's important
to note that the first element of the array has an index of 0. To begin working with arrays, consider
the following statement:
float[] weightArray;
This defines a variable called weightArray , which is an array of floating point numbers. Note the
square brackets ( [] ), which denote that the variable is an array. Although not recommended, an array
can also be declared as follows:
float weightArray[];
 
Search WWH ::




Custom Search