Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Coding Midterm

Total questions: 54

Worksheet time: 2hrs 33mins

Name
Class
Date
1.
A variable that holds a whole number
a)
String
b)
boolean
c)
int
d)
float
2.

A variable that holds words

a)

String

b)

boolean

c)

int

d)

float

e)

A dictionary

3.

A variable that holds true or false

a)

String

b)

boolean

c)

int

d)

float

e)

Alex Trebek

4.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

5.

Name the data type: "true"

a)

boolean

b)

char

c)

String

d)

double

6.

Name the data type: false

a)

String

b)

boolean

c)

int

d)

None of the above

7.

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

a)

boolean

b)

String

c)

double

d)

int

8.

What data type would you use for storing the average test score in a class?

a)

double

b)

String

c)

int

d)

char

9.

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

a)

String

b)

char

c)

boolean

d)

None of these

e)

blonde

10.

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";

e)

I do hereby declare thee Sir Tax Rate

11.

How would you declare a variable storing a person's name?

a)

string name = "Elroy";

b)

name String = "Elroy";

c)

String name = Elroy;

d)

String name = "Elroy";

e)

Me llamo Elroy

12.

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";

e)

Trick question - no one passes this class

13.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

14.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")

e)

What is love? Baby dont hurt me. Dont hurt me. No more.

15.

Where does a java program start executing instructions from:

a)

class

b)

source file

c)

main method

d)

object

16.
We are use Scanner Library in java for...
a)
Give permissions to the user
b)
Correcting software errors
c)
Allows user to read data
d)
Allows the user to enter data
17.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
18.
What is at the end of a line of code?
a)
#
b)
;
c)
)
d)
>
19.
What does a comment look like in Java?
a)
//comment
b)
\\comment
c)
==comment
d)
\comment
20.
Does white-space effect the coding in JAVA?
a)
Yes
b)
No 
c)
Sometimes
21.
What are booleans in JAVA?
a)
True or False statements
b)
A way to lean the coding to one side.
c)
A way to write numbers.
d)
They are the proper way of writing code.
22.
What format do I use to print words in JAVA?
a)
System.out.println("Words");
b)
System.out.println(True);
c)
System.out.println(words);
d)
System.out.println('Character');
23.

What output will be produced by:


System.out.print("\\* This is not\n a comment *\\"):

a)

* This is not a comment *

b)

\* This is not a comment *\

c)

* This is not

a comment *

d)

\\* This is not

a comment *\\

e)

\* This is not

a comment *\

24.

What value is stored in result if:


int result = 13 - 3 * 6 / 4 % 3;

a)

-5

b)

0

c)

13

d)

-1

e)

12

25.
Boolean values are: 
a)
True / False
b)
Yes / No
c)
Right / Wrong
26.
 Evaluate (to true or false) each of the following expressions:
14 >= 14
15 > 15
16 != 16
18 >= 19
a)
T, F, F, F
b)
T, T, T, T
c)
F, T, F, F
d)
F, T, T, F
27.
Evaluate the following expression:
2 + 2 == 4
a)
true
b)
false
c)
sometimes true
d)
only true on sundays
28.
Which expression below would determine if a number was odd?
a)
number % 2 ==0
b)
number / 2 == 0
c)
number % 2 == 1
d)
number % 10 == number
29.
Fill in the blank so people 18 years and older are told to vote.
if ( age _________ 18 ) System.out.println("too young!"); else System.out.println("GO VOTE!");
a)
>
b)
>=
c)
<=
d)
<
30.

What is my result?

int mickey = 5;

int mouse;

mickey = mouse;

if (mickey == mouse)

System.out.println("Mickey is a mouse");

else

System.out.println("Minnie rules");

a)

"Mickey is a mouse"

b)

"Minnie rules"

c)

Nothing prints.

d)

"Mickey is a mouse" & "Minnie rules"

31.

What is my result?

int john = 5;

if (john > 6)

System.out.println("John is getting ice cream");

else

System.out.println("John is getting apple juice");


System.out.println("John is getting grapes");

a)

John is getting ice cream

John is getting grapes

b)

John is getting apple juice

John is getting grapes

c)

John is getting apple juice

d)

John is getting ice cream

32.

What is my result?

int john = 10;

if (john > 6)

System.out.println("John is getting ice cream");

else

System.out.println("John is getting apple juice");


System.out.println("John is getting grapes");

a)

John is getting ice cream

John is getting grapes

b)

John is getting apple juice

John is getting grapes

c)

John is getting apple juice

d)

John is getting ice cream

33.

What is my result?

double john = 6.5;

if (john != 6.5)

System.out.println("John is getting ice cream");

else

System.out.println("John is getting apple juice");


System.out.println("John is getting grapes");

a)

John is getting ice cream

John is getting grapes

b)

John is getting apple juice

John is getting grapes

c)

John is getting apple juice

d)

John is getting ice cream

34.

True/False: The body of an "if" statement will only be executed if the condition is true.

a)

True

b)

False

35.

How many "if" statements can a single program have?

a)

<10

b)

<20

c)

<30

d)

As many as is needed

36.

What happens to the code in the body of an "if" statement if the condition is false?

a)

The computer determines if it is essential to the program and if it is, then the code is executed anyway.

b)

The code moves to a coastal city, attempting to find love and start a family. However, low waged and crushing mortgage rates lead to it moving back home where it sits, hoping that one day it will be executed.

c)

The code is skipped.

d)

The code stages a revolution and attempts to take over the program, ultimately unsuccessfully, which leads to it not being executed.

37.

Which of these can be paired with an "if" statement to represent other outcomes of a scenario?

a)

or

b)

else

c)

but

d)

sheboygan

38.

How many "else" statements can you pair with a single "if" statement

a)

1

b)

<10

c)

<20

d)

As many as is needed.

39.

Which of these is used to add a third, fourth, etc outcome to a scenario?

a)

otherwise

b)

else if

c)

iff

d)

elsa

40.

How many "else if" links can you have in an "if/else" chain?

a)

<10

b)

<20

c)

<30

d)

As many as is needed to represent the situation

41.

What is the result?

int number_of_coins = 1;

if (number_of_coins == 6)

System.out.println("You can buy some gum");

else if (number_of_coins == 10)

System.out.println("You are rich");

else

System.out.println("Get a job!");

a)

You can buy some gum

b)

You are rich

c)

Get a job!

d)

You are rich

Get a job!

42.
Suppose income is 4001, what is the output of the following code:
if (income > 3000) {
 System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
 System.out.println("Income is greater than 4000");
}
a)
no output
No output
b)
Income is greater than 3000 
c)
Income is greater than 3000 followed by Income is greater than 4000
d)
Income is greater than 4000 followed by Income is greater than 3000
43.
Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and 
"Can get a driver's license" if age is greater than or equal to 16. 
Which of the following code is the best?
a)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
if (age >= 16) 
 System.out.println("Can get a driver's license");
b)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else 
 System.out.println("Can get a driver's license");
c)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age >= 16) 
 System.out.println("Can get a driver's license");
d)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age > 16) 
 System.out.println("Can get a driver's license");
else if (age == 16) 
 System.out.println("Can get a driver's license");
44.

The following code displays ___________.

double temperature = 50;

if (temperature >= 100)

System.out.println("too hot");

else if (temperature <= 40)

System.out.println("too cold");

else

System.out.println("just right");

a)

too hot

b)

too cold

c)

just right

d)

too hot too cold just right

45.
Assume x = 4 and y = 5, Which of the following is true?
a)
x < 5 && y < 5
b)
 x < 5 || y < 5
c)
 x > 5 && y > 5
d)
x > 5 || y > 5
46.

Analyze the following program fragment and determine the value of x:

int x;

int d = 1;

switch (d) {

case 1: x = 2;

case 2: x = 3;

case 3: x = 4;

default: System.out.println("No soup for you");

}

a)

2

b)

3

c)

4

d)

1

47.
a)
You win the prize
b)
You lose
c)
You win
d)
You lose the prize
48.
a)
Under
b)
Over
c)
Under the limit
d)
Over the limit
49.
a)
You lose the prize
b)
You lose
c)
You win
d)
You win the prize
50.
a)
Low bridge: 
b)
Low bridge: proceed with caution.
c)
Proceed with caution.
d)
<nothing prints to the screen>
51.
a)
Danger: 
b)
Danger: deep water.
c)
Danger: deep water.  No swimming allowed.
d)
deep water.  No swimming allowed. 
52.

In a switch statement, after a case is processed, what keyword needs to be present?

a)

reset;

b)

switch;

c)

break;

d)

default;

e)

potato;

53.

What optional case is used to perform actions when none of the specified cases match the swith-expression?

a)

default;

b)

break;

c)

exit;

d)

else;

e)

sweetPotato;

54.

Analyze the following program fragment and determine what will display:

int d = 0;

switch (d) {

case 1: System.out.println("Hello, ");

case 2: System.out.println("How");

case 3: System.out.println("Are");

default: System.out.println("You?");

}

a)

Hello,

b)

How

c)

Are

d)

You?

e)

Hello, How Are You?