AP Computer Science Lesson Introductory Java Language Features (2)
Words
81
Reading
1 min
Listen
Play
9y
Notes Intro Java Language Features - Operators 8/16
####Arithmetic Operators:
| "+" | Addition | - |
|---|---|---|
| "-" | Subtraction | - |
| "*" | Multiplication | - |
| "/" | Division | - |
| "%" | Mod (remainder) | Ex. 11 % 8 = 3 |
** Keep in mind, if you use int for 5/2... It will give you an integer! So, use double as its type.
Relational Operators:
| == | equal to | Ex. if (x == 100) |
|---|---|---|
| != | not equal to | Ex. if (x != 100) |
| > | greater than | |
| < | less than | |
| >= | greater than or equal to | |
| <= | less than or equal to |
** Use these when you may need to use different operations to different types of numbers.
Logical Operators:
** AND means both have to be true.
** OR means one has to be true.
Truth Tables
Assignment Operators:
| = | x = 2 | - |
|---|---|---|
| += | x += 4 | this means x = x + 4 |
| -= | x -= 4 | this means x = x - 4 |
| *= | x *= 4 | this means x = x * 4 |
| /= | x /= 4 | this means x = x / 4 |
| %= | x %= 4 | this means x = x % 4 |
Increment and Decrement Operators:
| ++ | i++ | means i = i + 1 |
|---|---|---|
| -- | i-- | means i = i - 1 |
** Here is a mathematical example where we could use this:
A mathematical program:
Output (what the user would see):
Solving 5+3*2-2^2:
7
Question for the Students
Make a program with the output:
Hello World.
My name is ______.
My favorite movie is ______.
Answer:
Thank you for viewing Steemers! I am happy to provide my lesson plans for you!