









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to variables, constants, and assignment operators in java. It covers topics such as declaration and initialization, constants and literals, the assignment operator, and increment operators. The document also explains the order of operations and the difference between unary and binary operators.
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!
I fail at binary Monday lab on website by Sunday
To use variables two things must be done:
int x, y, z; x = 2; y = 3; z = 4; int x=2, y=3, z=4; Same as: Declaration Initialization Variables can be declared anywhere (preferably at start)
= is the assignment operator The object to the right of the equals sign is stored into the object in the left int x, int y; y = 2; x = y+2;
= is NOT a mathematic equals x=3; x=4; This does not mean 3=
What does this code do? int x = 2; y = 3; y=x; x=y; What was the intention of this code?
= is the assignment operator The object to the right of the equals sign is stored into the object in the left int x, int y; y = 2; x = y+2;
Two types of increment operators: x++; // increments after command vs ++x; // increments before command (see IncrementOperator.java)
The following format is general for common operations: variable (operator)= expression variable = variable (operator) expression Examples: x+=2 x = x + 2 x*=y+2 x = x * (y + 2) (see AssignmentOperator.java)
Binary operators need two arguments Examples: (see BinaryOperators.java) 2+3, 5/2 and 6% Unary operators require only one argument: Examples: (see UnaryOperators.java) +x, x++, !x (! is the logical inversion operator for booleans)
When multiple operations have the same precedence level: Binary operations go from left to right Unary operations go right to left;