Copy of Arrays and Jump
Copy of Arrays and Jump
L 2.8
Array Creation
⚫After declaration, no array actually exists.
⚫In order to create an array, we use the new
operator:
type array-variable[];
array-variable = new type[size];
⚫This creates a new array to hold size elements of
type type, which reference will be kept in the
variable array-variable.
Array Indexing
L 2.13
Arithmetic assignments
+= v += expr; v = v + expr ;
-= v -=expr; v = v - expr ;
*= v *= expr; v = v * expr ;
/= v /= expr; v = v / expr ;
%= v %= expr; v = v % expr ;
Basic Arithmetic Operators
+ op1 + op2 ADD
L 2.15
Relational operator
== Equals to Apply to any type
! ! op Logical NOT
>> op1 >> op2 Shifts all bits in op1 right by the value of
op2
<< op1 << op2 Shifts all bits in op1 left by the value of
op2
Expressions
⚫An expression is a construct made up of variables,
operators, and method invocations, which are
constructed according to the syntax of the language, that
evaluates to a single value.
⚫Examples of expressions are in bold below:
int number = 0;
anArray[0] = 100;
System.out.println ("Element 1 at index 0: " +
anArray[0]);
int result = 1 + 2; // result is now 3 if(value1 ==
value2)
System.out.println("value1 == value2");
L 2.19
Expressions
⚫ The data type of the value returned by an expression depends on
the elements used in the expression.
⚫ The expression number = 0 returns an int because the
assignment operator returns a value of the same data type as its
left-hand operand; in this case, number is an int.
⚫ As you can see from the other expressions, an expression can
return other types of values as well, such as boolean or String.
The Java programming language allows you to construct
compound expressions from various smaller expressions as long
as the data type required by one part of the expression matches
the data type of the other.
⚫ Here's an example of a compound expression: 1*2*3
Control Statements
L 3.3
Jump Statements