Search Header Logo
Data Types & Variables Review

Data Types & Variables Review

Assessment

Presentation

Computers

12th Grade

Practice Problem

Easy

Created by

Nichole Niebur

Used 5+ times

FREE Resource

10 Slides • 8 Questions

1

media

Data Types and Variables Review

2

media
media

Data types can be categorized as either primitive or reference

Primitive

Reference

3

Labelling

Label the following Data Types

(I know some can be "right" but it will make it wrong because it's a computer program, try to think of size order to help.)

Drag labels to their correct position on the image
boolean
short
char
byte
long
int
float
Array
double
String

4

Variables

media

A variable is a piece of the computer's memory that is given a name and a type, and can store a value.

5

media
media
media

State its name and type

Declare It

Store a value into it

Initialize It

Print it or use it as part of an expression.

Use It

​Steps for using a variable

6

media

Set aside memory for storing a value.

! Variables must be declared before they can be used

Syntax = type <name>;
*The name is an identifier

Declaration

7

Multiple Choice

Which of the following properly DECLARES a variable?

1

int x = 5

2

byte y

3

myGPA;

4

float myGPA;

8

media

Storing a value into a variable

! can be done in one step OR separately

Syntax = name = expression;
int x; or int x = 3;
x = 3;

Assignment

9

Multiple Choice

Which of the following properly ASSIGNS a variable?

1

x = 5

2

byte y = 2

3

myGPA = 4.0;

4

float myGPA = 4.0

10

media

Once given a value, a variable can be used in expressions

System.out.println("x is " + x);

! you can assign a value more than once

int x = 3; //here x is 3
x = 4 + 7; //now x is 11

Using Variables

11

media

=
This is the assignment operator!
It does not mean equals, instead it means "stores the value of "

NOT EQUALS!

12

Fill in the Blanks

13

Multiple Variables

Multiple variables of the same type can be declared and initialized at the same time.

Syntax:
int x, y, z; //declares three integers
int a = 1, b = 2, c = 3; //declare and initialize three
// integers

14

double myGPA = 4;


hmmm... can you guess what's coming?

An int value can be stored in a double variable, but the value is converted to the equivalent type.

int x = 2.5; //ERROR


incompatible types

A variable can only store a value of its own type.

Assignment and Types

15

Math Response

What does this program print?

double myGPA = 4;

System.out.println(myGPA);

Type answer here
Deg°
Rad

16

Poll

Does this cause an error?

int x;

7 = x;

Yes

No

17

Poll

Does this cause an error?

int x;

System.out.println(x);

Yes

No

18

Poll

Does this cause an error?

int x;

int x = 3;

Yes

No

media

Data Types and Variables Review

Show answer

Auto Play

Slide 1 / 18

SLIDE