Variables & types
intfor integers (…, -2, -1, 0, 1, 2, …)
floatfor “floating point” values (i.e. decimal values like -0.5 or 1.23040E-23)
charfor single characters/symbols (e.g.,
String(capitalized) for “strings” (e.g.,
booleanfor true/false values
Here are the rules for naming variables:
1 to 255 characters
must begin with a letter or _
after the first letter or _, can contain numbers
uppercase and lowercase letters are considered different (e.g. xyz is not the same variable as Xyz)
“reserved” words cannot be used (e.g. “void” “if” etc.)
Here are the normal math operators that work on integers and floating point numbers:
-(subtract; or a negative number, e.g.
int x = -5)
Here are somewhat-unique math operators that work with integers:
13 / 5is 2 because 5 goes into 13 two times)
13 % 5is 3 because the remainder of 5/13 is 2)
/ works as you would expect with floating point numbers
1.2 / 5.6 is about 0.214).
Precedence works the same as you would expect:
* / % happen before
+ - so
(5 + 6 % 4 - (3 + 4) / 2) equals 4 as you would expect. You
can use parentheses to clarify the math.
You can use the following shorthand for changing the values of variables. The shorthand form is shown, then the equivalent form is described in comments.
Variables of type
boolean have the following special operators:
pow(a, b)— raise
ato the power
bshould have type
exp(a)— raise Euler’s number e to the power
log(a)— find the natural logarithm of
sqrt(a)— find the square root of
sin(a)— the result of sine(a) (a is a float, in radians)
What you’ll need to know for test 1
Identify the appropriate type for specific values. E.g., what’s the right type for a variable that should hold values 1, 2, 3, … What’s the right type for a variable that should hold the value 99.99? What’s the right type for the phrase “Neil Diamond”? What’s the right type for a true/false value? etc.
Know how to create variables of all the types mentioned in these notes, and how to set their values.
Know how to do arithmetic with integer and float values.
Know how to find the square root of a value, raise a value to another value (x^y), find the cosine of a value, etc. I’ll give you easy questions here so that you don’t have to memorize all the available math operations.
Know the arithmetic shorthand, like
Know how to check if two values/variables are equal (with
Know how to express complex statements with boolean variables. E.g., how do you write, “p is true, but neither q nor r is true”?