Save
Tech
2. Variables
Save
Share
Learn
Content
Leaderboard
Learn
Created by
raquelle <33
Visit profile
Cards (20)
What are the 5 types of data that can be a variable?
int
,
float
,
char
,
String
and
boolean
What type of variable data is only a whole number?
int
What type of variable data can be any number?
float
What type of variable data can be one character?
char
What type of variable data can be multiple characters?
String
The requirements of a variable identifier are: They must start with a
letter
, and can only contain
letters
,
numbers
, and
underscores.
What type of variable data is true or false?
boolean
size(400,400);
boolean a = false;
if (!a){
rect(120, 80, 200, 200);
}
a = true;
if (a) {
line(80, 40, 360, 320);
line(80, 320, 360, 40);
}
(This is an example of what type of variable?)
boolean
Write a variable identifier to hold the sum of a bunch of numbers:
int
sum
=
0;
Write a variable identifier which will be used to calculate the product of a set of numbers: float product
=
1; or
int
product = 1;
Write a variable identifier that will hold the name of a character:
String
name
=
"your_name";
The 5 variable operators are:
+
-
*
/
%
What does % do?
It is the
modular
operator
, which returns the
remainder
of a
division
operation.
The four assignment operators are:
+=
-=
*=
/=
Write a variable to store 2x + 3y − z: int result
=
2
*
x
+
3
*
y
-
z
;
Write a variable to store 2×3 / 4:
float
result
=
(
2
*
3
)
/
4
;
Write a variable to store 4 % 3:
int
remainder =
4
%
3
;
Write a line of code that will add 7 to a variable and store the result in the same variable:
int
num
=
num
+
7
;
or
num
+=
7
;
Write the shortest line of code to increment a variable by 1:
num++
;
Write the shortest line of code to decrement a variable by 1:
num--
;