Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Intro to Programming: data types, if/else, and loops

Total questions: 15

Worksheet time: 12mins

Name
Class
Date
1.

Click ALL answers which result in an "X" printed.

a)

a = 3, b = 3, c = 3

b)

a = 5, b = 4, c = 7

c)

a = 1, b = 3, c = 5

d)

a = 6, b = 4, c = 3

e)

a = 5, b = 5, c = 3

2.

What is output?

a)

Jackson

b)

Memorial

c)

JacksonMemorial

d)

There is no ouptut

3.

Which of the following conditional statements is executed?

a)

The if statement

if (z == 3) { ... }

b)

The else if statement

else if (z < 5) { ... }

c)

The else statement

else { ... }

d)

None of them

4.

What will be the value of after this set of conditional statements?

a += 2; means a = a + 2;

a += 3; means a = a + 3;

a)

7

b)

9

c)

10

d)

4

5.

Which of these is the correct format for an "if/else" statement?

a)
b)
c)
d)
6.

Which of these is the proper format of an "else/if" chain statement?

a)
b)
c)
7.

Which of the following includes the correct syntax for a for loop?

a)

for(int i = 0, i<10, i++)

b)

for(int i =0, run = 10)

c)

for(int i = 0; run = 10)

d)

for(int i = 0; i < 10; i++)

8.

for(int i; i<10; i++) {} Why won’t this code segment run?

a)

There is a missing semicolon at the end.

b)

For should be capitalized

c)

The person did not set the beginning value of i.

d)

The person did not set the ending value of i.

9.

Loop

a)

Loops that have a predetermined beginning, end, and increment (step interval).

b)

The action of doing something over and over again.

c)

A description of the behavior of a command, function, library, API, etc.

d)

To repeat in order to achieve, or get closer to, a desired goal.

10.

Name the data type: false

a)

String

b)

boolean

c)

int

d)

None of the above

11.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

12.

What data type would you use to store names of students?

a)

String

b)

char

c)

boolean

d)

None of these

13.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

14.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

15.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";