Chapters 1-3
list of boolean operators
*** also there is an exclusive or (^)
int numberOfDays; numberOfDays = 7; - Declare and initialize using 1 line - Add 10
*int numberOfDays = 7; numberOfDays = numberOfDays + 10;*
Element
An individual item in an array
precedence in boolean/logical operators
some ops have high precedence than other; parentheses can be used to change the precedence (like in math)
Array
A(n) ______ is a data structure (type of memory layout) that stores a collection of individual values that are of the same data type.
Why are arrays useful?
Arrays are useful because instead of having to separately store related information in different variables (named memory locations), you can store them—as a collection—in just one variable. It is more efficient for a program to access and process the information in an array, than it is to deal with many separate variables. All of the items placed into an array are automatically stored in adjacent memory locations. As the program retrieves the value of each item (or "element") of an array, it simply moves from one memory location to the very next—in a sequential manner. It doesn't have to keep jumping around to widely scattered memory locations in order to retrieve each item's value.
Initializing a variable
Before a variable can be used it must be given an initial value. This is called _______the variable, and is usually done right after we declare the variable. If we try to use a variable without first giving it a value *int numberOfDays; //try and add 10 to the value of numberOfDays numberOfDays = numberOfDays + 10;* the compiler will throw an error the correct way is: *int numberOfDays; numberOfDays = 7; * now you can add 10 to the variable
What do you need to declare a variable
all that is needed is the data type followed by the variable name EX: int numberOfDays; *Now that it has been declared, numberOfDays can only ever hold values that match the definition of the data type*
relational operators
also known as comparison operators, compares 2 values in a boolean
boolean operators- definition
also known as logical operators; used to create a compound boolean statement
augmented assignment operators
special type of operator we use to make our code shorter very often the current value of a variable is used, modified, and then reassigned to the same variable count = count + 1; instead of using the operator +, we can save time with the augmented assignment operator += count += 1;
boolean data type
data type that declares a variable with the value either true, or false *boolean* lightsOn= *true*; //boolean data type declared basically when we compare two values (such as whether a radius is greater than 0 or equal to 0) we first use *relational operators* (also known as comparison operators) to compare 2 values. the results of this comparison is a *boolean value* (and is either true or false) *if a boolean statement/expression is true, an if statement will execute*
boolean operator *!*
if an *expression* is true, *! expression* will be false
Variables
memory locations
operators
the +, -, *, /, and % that we put in the expression (assignment statement)
assignment statements
the statement in which we assign a value to a variable (can be initializing or when we are changing a variable); basically it's the expression after the = sign x = x + 1;
Declaring a variable
to state what type of value a specific variable (memory location) can hold Ex: int numberOfDays;
Increment and decrement operators
used to increment and decrement a variable by 1 *ask alex the difference between the pre and post var (++var vs. var++)*