WorksheetsCoding Midterm
Total questions: 54
Worksheet time: 2hrs 33mins
A variable that holds words
String
boolean
int
float
A dictionary
A variable that holds true or false
String
boolean
int
float
Alex Trebek
Name the data type: 1.0
double
int
char
boolean
Name the data type: "true"
boolean
char
String
double
Name the data type: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What data type would you use for storing the average test score in a class?
double
String
int
char
What data type would you use to store names of students?
String
char
boolean
None of these
blonde
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
I do hereby declare thee Sir Tax Rate
How would you declare a variable storing a person's name?
string name = "Elroy";
name String = "Elroy";
String name = Elroy;
String name = "Elroy";
Me llamo Elroy
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Trick question - no one passes this class
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
What prints out "I love Java" successfully?
System.out.println(I love Java);
Systemoutprintln("I love Java);
System.out.println("I love" + " Java");
System.out.println("I love Java")
What is love? Baby dont hurt me. Dont hurt me. No more.
Where does a java program start executing instructions from:
class
source file
main method
object
What output will be produced by:
System.out.print("\\* This is not\n a comment *\\"):
* This is not a comment *
\* This is not a comment *\
* This is not
a comment *
\\* This is not
a comment *\\
\* This is not
a comment *\
What value is stored in result if:
int result = 13 - 3 * 6 / 4 % 3;
-5
0
13
-1
12
14 >= 14
15 > 15
16 != 16
18 >= 19
2 + 2 == 4
if ( age _________ 18 ) System.out.println("too young!"); else System.out.println("GO VOTE!");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");
"Mickey is a mouse"
"Minnie rules"
Nothing prints.
"Mickey is a mouse" & "Minnie rules"
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");
John is getting ice cream
John is getting grapes
John is getting apple juice
John is getting grapes
John is getting apple juice
John is getting ice cream
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");
John is getting ice cream
John is getting grapes
John is getting apple juice
John is getting grapes
John is getting apple juice
John is getting ice cream
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");
John is getting ice cream
John is getting grapes
John is getting apple juice
John is getting grapes
John is getting apple juice
John is getting ice cream
True/False: The body of an "if" statement will only be executed if the condition is true.
True
False
How many "if" statements can a single program have?
<10
<20
<30
As many as is needed
What happens to the code in the body of an "if" statement if the condition is false?
The computer determines if it is essential to the program and if it is, then the code is executed anyway.
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.
The code is skipped.
The code stages a revolution and attempts to take over the program, ultimately unsuccessfully, which leads to it not being executed.
Which of these can be paired with an "if" statement to represent other outcomes of a scenario?
or
else
but
sheboygan
How many "else" statements can you pair with a single "if" statement
1
<10
<20
As many as is needed.
Which of these is used to add a third, fourth, etc outcome to a scenario?
otherwise
else if
iff
elsa
How many "else if" links can you have in an "if/else" chain?
<10
<20
<30
As many as is needed to represent the situation
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!");
You can buy some gum
You are rich
Get a job!
You are rich
Get a job!
if (income > 3000) {
System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
System.out.println("Income is greater than 4000");
}
No output
"Can get a driver's license" if age is greater than or equal to 16.
Which of the following code is the best?
System.out.println("Cannot get a driver's license");
if (age >= 16)
System.out.println("Can get a driver's license");
System.out.println("Cannot get a driver's license");
else
System.out.println("Can get a driver's license");
System.out.println("Cannot get a driver's license");
else if (age >= 16)
System.out.println("Can get a driver's license");
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");
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");
too hot
too cold
just right
too hot too cold just right
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");
}
2
3
4
1
In a switch statement, after a case is processed, what keyword needs to be present?
reset;
switch;
break;
default;
potato;
What optional case is used to perform actions when none of the specified cases match the swith-expression?
default;
break;
exit;
else;
sweetPotato;
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?");
}
Hello,
How
Are
You?
Hello, How Are You?
