Intro to Computer Programming- Data Types, Operators, and Expressions(Part 2)
/
DIVISION OPERATOR. Used to find the quotient.
=
Equal to(Don't confuse this with the assignment operator.
operator precedence
PLEASE ( ) EXCUSE //DON'T WORRY ABOUT THESEFOR NOWMY DEAR MAD * / %AUNT SALLY + -
+(CONCATENATION)
Used to combine STRINGS and other DATA TYPES
What is an Integrated Development Environment(IDE)?
•A software program used by PROGRAMMERS that makes PROGRAMMING easier by providing certain tools and features, like DEBUGGING, or VERSION CONTROL. •In CSE 1300, we'll be using Repl.it—an online IDE. In CSE 1231L, Java students will use jGrasp.
Liberal
•A specific VALUE assigned to a VARIABLE or a CONSTANT. (int age = 2, the Liberal would be 2).
&&
•AND •Both statements must be true in order to return true. If either statement is false the results are false. •In Python, simply type the word and in lowercase letters.
What is a Boolean expression?
•An EXPRESSION (CONDITION) is any legal combination of symbols that represents a value. •Every EXPRESSION consists of at least one OPERAND and can have one or more OPERATORS. •OPERANDS are values, whereas OPERATORS are symbols that represent particular actions. •Therefore, a BOOLEAN EXPRESSION is simply an EXPRESSION that evaluates to true or false.
DANGER, WILL ROBINSON: AVOIDING COMMON ERRORS
•DO NOT use spaces between arithmetic operators and assignment operator when using shortcut operators. •When using a shortcut operator, the arithmetic operator will always go before the assignment operator.
Example of Overwriting a Variable:
// Declare Variables String firstName = "Kaleigh"; //Overwrite firstName Variable firstName = "Brian"; //Print System.out.println(firstName);
Example of Combining Variables:
// Declare Variables String firstName = "Kaleigh"; String lastName = "Kendrick"; // Combine Variables String fullName = firstName + " " + lastName;
Example of Concatenation:
// Declare Variables String item = "apple"; float price = 1.05; // Print concatenated message System.out.println("The " + item + " costs $ " + price);
Example of Escape Sequence:
// Declare a String Variable String item = "Hello!"; //Escape sequence String item = "I said \"Hello!\""
Order of precedence (operations).
1.Arithmetic Operators (PEMDMAS) 2.Relational Operators 3.Logical Operators
+
ADDITION OPERATOR. Used for addition.
>=
Greater than or equal.
>
Greater than.
<
Less than.
<=
Less-than or Equal.
*
MULTIPLICATION OPERATOR. Used for multiplication
!=
Not equal to.
-
SUBTRACTION OPERATOR. Used for subtraction.
What is a String?
•It is not a PRIMITIVE DATA TYPE. •A set of characters (whereas a CHAR is a single character). •Strings are enclosed in double quotes. •Can contain any valid character, including special characters. If you use quotes inside of a string as part of a string, you need to use an escape sequence(A character preceded by a backslash (\)).
%
•MODULUS OPERATOR. Used to find the remainder. •Only use the MODULUS OPERATOR when dividing INTEGER data types.
!
•NOT •! Is an unary operator—it only operates on one OPERAND. •In Python, simply type the word not in lowercase letters.
What are the logical operators?
•OPERATORS that allow a program to make a decision based on multiple CONDITIONS using BOOLEAN values. •Primarily used to control program FLOW.
||
•OR •Used when one statement may be false. •If either statement (or both) is true, the results are true. •NOTE: If the first statement evaluates as true, the program doesn't need to check the second statement. In Python, simply type the word or in lowercase letters.
What are the comparison operators?
•Operators that compare EXPRESSIONS. •Also known as RELATIONAL OPERATORS or EQUALITY OPERATORS. •When we use COMPARISON OPERATORS, we'll return a BOOLEAN result.
Static
•Types are checked during compile time. •You MUST declare the data types for your variables before you use them.
Dynamic
•Types are checked during run-time. •You do not declare the data types for your variables before you use them.