0% found this document useful (0 votes)
22 views

AP Computer Science: Lesson 1 Types and Variables

This document introduces common variable types in AP Computer Science including integers, doubles, Booleans, and final variables. Integers are used to store whole numbers, doubles are for decimal values, Booleans hold true or false values, and final variables are constants. Integers are typically used for counting while doubles can measure values. Variables are assigned values using the equal sign and can be incremented or decremented as shortcuts.

Uploaded by

Mark Hilliker
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

AP Computer Science: Lesson 1 Types and Variables

This document introduces common variable types in AP Computer Science including integers, doubles, Booleans, and final variables. Integers are used to store whole numbers, doubles are for decimal values, Booleans hold true or false values, and final variables are constants. Integers are typically used for counting while doubles can measure values. Variables are assigned values using the equal sign and can be incremented or decremented as shortcuts.

Uploaded by

Mark Hilliker
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

AP Computer Science

Lesson 1 Types and Variables

Types
Integers (int): a fundamental type used to define numeric variables holding whole numbers
-n,,-3,-2,-1,0,1,2,3,,n where n=-1+2^31 int i=0; Typically Counting Variables

Types ctd.
Doubles: a double precision floating point number. (ignore formal definition)
Any value with a decimal Ex: 0.1, 3.14, 2., etc. double e=2.718;

Int vs Double
int Used to count Answers How many? Ex:
Number of People Number of Items in a List Number of Steps to Solve a Puzzle

double Used to measure Answers How Much? Ex:


Balance of Bank Account Weight, Mass, Volume Grade In Class

Types ctd.
Boolean: used to hold values of true or false
Most basic data type Typically the result of a comparison or test Ex: int a = 0; int b = 3; boolean c = b>a;
Here, true is assigned to c

Final Variables
Final Variables: user-defined constants that do not change after assignment
Variables that you want fixed throughout the program Typically in all caps with underscores for spaces Ex: final double TAX_RATE = .075; final double MONTHLY_FEE = 20.00; final int MIN_CLASS_SIZE = 15;

Assignment
Assign values to variables using equal sign
int x=0; double rate = .05;

Shortcuts:
q= q + 1 is the same as q+=1 same for all other operators Incrementing/decrementing is i++ or j- Same as i=i+1 and j=j-1 respectively

You might also like