Java Levels 0-2 Flashcards
strings
“string”
must have quotation marks
String
integers
whole #’s w/ no decimal point
weird math
int
doubles/floating-point values
real numbers
numbers w/ decimal points
double
booleans
true/false (LOWER CASE)
boolean
operators
the symbols that we use to perform calculations on diff values
arithmetic operators
+ - * / %
parenthesis used same as in math
order of operations same
concatenation
if you “add” anything to a string, it will stick that value on to the string
“Hello” + “werld” = “Hellowerld”
50 + “8” = “508”
“Zoobah” + 0.5 * 3 = “Zoobah1.5”
integer division
when 2 integers r divided, the result is always an integer
will chop off decimal part NOT round
6/4 = 1
2 / 3 = 0
1 / 5.0 = 0.2 (if ether of the values is a double, will do normal division)
modulus division
only works on integers
gives the remainder of the first number divided by the second number
6 % 4 = 2
12 % 3 = 0
3 % 4 = 3 (if 1st # is less than 2nd #, answer is always 1st number)
variables
named containers for values
fundamental tool for programming
must be declared
variable declarations
statements, so must end in semicolons
int blah;
double aVariable;
String porty;
int ting, roo;
assignments/statements
putting a value into a variable for storage
=
blah = 10;
aVariable = 0.6;
porty = “Teapot”;
ting = 10 / 5;
roo = blah / ting; can use other variables in math expression and assignment statements
combining declarations & assignments
int abc = 12, def = 801;
double xyz = 10.5;
String ijk = “pointy hat”;
self assignments
can use a variable on the right hand side of its own assignment
int fumu = 10;
fumu = fumu + 3;
fumu = fumu - 5;
type mismatch
when variables r assigned values that don’t match their type
int abc = 10.0;
double def = 3; this works tho cuz Java can turn integers into doubles when necessary