(in slow motion)
Use the arrow keys to navigate. Press 'm' to see all the slides.
We will use variables to manipulate information about them
Variables will store information (about apples in our example)
int
, float
, double
, char
, boolean
String
int
type is for whole numbers (integer numbers)float
and double
types are for real numberschar
type is for single text characters (a letter, a punctuation symbol, etc)String
type is for sequences of text characters (a name, an address, a short story, etc)boolean
type is for assigning yes/no answersTo use variables in Java we need to declare them
TYPE
variable_name;
TYPE
variable_name = INITIAL_VALUE;
Sidenote:
Comments are ignored by the computer
int
typefloat
typedouble
typechar
typechar
values go in single quotes
String
typeString
values go in double quotes
boolean
typeboolean
typeWe can assign values to variables
We can accumulate values in variables
We can do mathematical operations with number types
OPERATOR
variable_2 +
, -
: Addition , Subtractions *
, /
: Multiplication , Division %
: Remainder of division OPERATOR
variable_1, variable_1OPERATOR
++
, --
: Increase variable value by 1, decrease variable value by 1 Statements for which we can answer yes or no
Determine the truth value of a statement: true
or false
Comparisons are a kind of logical expressions
>
, <
: Greater than, Less than >=
, <=
: Greater or equal, Less than or equal ==
, !=
: Equal, Different Comparisons are a kind of logical expressions
&&
: AND ||
: OR R: The box contains red apples
G: The box contains green apples
What is the truth value of R &&
G for each box?
What is the truth value of R ||
G for each box?
We can use the truth values of logical expressions to conditionally execute code
Example: A computer program for putting apples in the appropriate shelf space
if
the apple is rotten
then
it goes in the garbage bin
else
it goes in one of the shelves
if
the apple is rotten
then
it goes in the garbage bin
else if
it is not rotten
then
it goes in one of the top shelves
/