Warm-up: Monday, February 24
description
Transcript of Warm-up: Monday, February 24
![Page 1: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/1.jpg)
+Warm-up: Monday, February 24 In outputting, what does “\n” do?
In outputting, what is the difference between the System.out.print( ) command and the Serial.out.println( ) command?
![Page 2: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/2.jpg)
+Warm-up: Monday, February 24 In outputting, what does “\n” do?
Goes to the next line; like hitting “enter”
In outputting, what is the difference between the System.out.print( ) command and the Serial.out.println( ) command? print( ) stays on the same line println( ) will go to the next line
![Page 3: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/3.jpg)
+
Arithmetic OperatorsPAP Computer Science, Cycle
5
![Page 4: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/4.jpg)
+8 Mathematical Operators Addition (+)Subtraction (-)Multiplication (*)Division (/)Modulus (%)Exponent (^) Increment (++)Decrement (--)
![Page 5: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/5.jpg)
+Addition, Subtraction, MultiplicationThese operators work identically in
programming as in traditional math
5 + 8 1310 – 4 64 * 3 12
![Page 6: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/6.jpg)
+Division Works differently for integers (whole
numbers) and decimals If operands are integers, the answer will be
an integer If operands are decimals, the answer will be
a decimal
11 / 2 5 11.0 / 2.0 5.5
![Page 7: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/7.jpg)
+Modulus (%)Modulus returns the remainder from
divisionExample: 26 % 5 1 26 / 5 5
![Page 8: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/8.jpg)
+Incrementing (++)
Increases the value of a variable by 1
Exampleint x = 5;x++;System.out.print(x) 6
![Page 9: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/9.jpg)
+Decrementing (--)
Decreases the value of a variable by 1
Exampleint x = 5;x--;System.out.print(x) 4
![Page 10: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/10.jpg)
+Pre- and Post-Incrementing When incrementing/decrementing, you can
put the operator before or after the variable
Exampleint x = 5; int y = 5;x++; ++y; x 6 y 6
![Page 11: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/11.jpg)
+Pre- and Post-IncrementingExample:
int x = 5;int y = x++;
x 6 y 5Example:
int x = 5;int y = ++x;
x 6 y 6
![Page 12: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/12.jpg)
+Order of Operations
( ) •Parenthesis
++ --
•Increment•Decrement
^ •Exponents
* / %•Multiplication•Division•Modulus
+ - •Addition•Subtraction
![Page 13: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/13.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 6
![Page 14: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/14.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 6
![Page 15: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/15.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 6
![Page 16: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/16.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 6
![Page 17: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/17.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
![Page 18: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/18.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
![Page 19: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/19.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
21 – 6 + 2 + 6
![Page 20: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/20.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
21 – 6 + 2 + 6
![Page 21: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/21.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
21 – 6 + 2 + 615 + 8
![Page 22: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/22.jpg)
+OOO Example
3 * 7 – 6 + 2 * 5 / 4 + 621 – 6 + 2 * 5 / 4 + 621 – 6 + 10 / 4 + 6
21 – 6 + 2 + 615 + 8
23
![Page 23: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/23.jpg)
+Warm-up: Tuesday, Feb 25
What does the % operator return?
int x = 6;x++;
What does ‘x’ equal now?
![Page 24: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/24.jpg)
+
Creating Variables
PAP Computer Science, Cycle 5
![Page 25: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/25.jpg)
+Variables
Variables are place-holders for values Storage locations
They reference a single number, character, or String, and can be called by their name.
Example: X = 5 Y = X + 5;
![Page 26: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/26.jpg)
+Declaring a Variable
Variables must be declared with two things: Data type Name
Initializing a variable (giving it a value) is NOT required when declaring a variable
![Page 27: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/27.jpg)
+Declaring/Initializing a VariableExample 1
int x;x = 5;
Example 2int x = 5;
![Page 28: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/28.jpg)
+Initializing a Variable
Variable name ALWAYS goes on the left
x = 5 NOT 5 = x
y = xSets y to whatever is stored in x
![Page 29: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/29.jpg)
+Naming a VariableNames in Java must follow certain rules
Naming conventions hold true for variables, methods, classes, etc
1. Cannot be a reserved word int, float, double, char, void, public, static,
return2. Can only consist of letters, numbers, _, $3. Cannot begin with a number4. Case sensitive
X != x VAR != var Test != test
![Page 30: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/30.jpg)
+Legal Identifiers
Variablestrnum_of_books$Amount integer3convert2fahr
![Page 31: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/31.jpg)
+Illegal Identifiers (Names)employee salary
Spaces are not allowedHello!
! is not allowedone+two
+ is not allowed2nd
Cannot begin an identifier with a number
![Page 32: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/32.jpg)
+Data TypesData types refer to the type of data that
will be stored in the variableLets the computer know how much
memory it needs to set aside for the variable
Data Types Int, Short, or Long (whole numbers) Float or Double (decimals) Byte (binary byte) Char (single character) Boolean (true/false)
![Page 33: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/33.jpg)
+Int, Short, LongUsed for whole numbers
Short (16 bits of memory) -32,768 to 32,767
Int (32 bits of memory) -2,147,483,648 to 2,147,483,647
Long (64 bits of memory) -263 to 263
![Page 34: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/34.jpg)
+Float and DoubleUsed for decimal point numbers
Float (32 bits) -3.4 x 1038 to 3.4 x 1038
6 to 7 digits of precision (decimal places)Double (64 bits)
-1.7 x 10308 to 1.7 x 10308
15 digits of precision (decimal places)
![Page 35: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/35.jpg)
+Byte, Char, BooleanByte (8 bits)
Used for binary bytes (B11001101)
Char (16 bits) Used for characters (‘A’)
Boolean (1 bit) True or false
![Page 36: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/36.jpg)
+ Using Variables in Codepublic class Variables
{
public static void main(String[ ] args)
{
int test1 = 90;
float test2 = 86.34;
int test3 = 23;
float sum = test1+test2+test3;
System.out.println(“Sum = “ + sum);
}
}
![Page 37: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/37.jpg)
+Warm-up: Wednesday, Feb 26Write the code to declare a variable
named “number” that contains the number 45.46
![Page 38: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/38.jpg)
+
Strings
PAP-Computer Science, Cycle 5
![Page 39: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/39.jpg)
+Strings
List of multiple charactersAlso known as
Character array Character string String literal String constant
In Java, String is a special class
![Page 40: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/40.jpg)
+String ClassAs a class, a String has certain properties
and methodsProperties
Length – how many letters in the String? Letter position
Methods compareTo startsWith endWith
![Page 41: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/41.jpg)
+Declaring Strings
Works much the same way as declaring any other variable
Needs data type and a nameValue is optional
![Page 42: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/42.jpg)
+Declaring a String
String name = “Ms. Alexander”;
String message = “Good luck on your test!”;
String weather = “It is sunny outside.”;
![Page 43: Warm-up: Monday, February 24](https://reader035.fdocuments.net/reader035/viewer/2022062305/568166a2550346895dda8cd0/html5/thumbnails/43.jpg)
+Example Code - Stringspublic class Example
{
public static void main(String[] args)
{
int value = 56;
String str = “Your value is “;
System.out.println(str + value);
}
}