Java SE 11: Expressions, Arrays, & Loops Flashcards
Select the possible values returned by a Boolean expression.
▢ 1
▢ 0
▢ true
▢ 2
▢ false
▢ no
▢ yes
1
0
☑ true
2
☑ false
no
yes
C Less than or equal to
A Equal to
B Not equal to
D Greater than or equal to
Select the response which simplifies the following code.
boolean largeVenue;
if (attendees >= 5) {
largeVenue = true;
}
else {
largeVenue = false;
}
largeVenue = (attendees * true + 5);
largeVenue = (attendees *= 5);
largeVenue = (attendees >= 5);
largeVenue = attendees;
largeVenue = (attendees >= 5);
What is the output printed by the following code?
int hoursNeeded = 5;
int hoursAvailable = 5;
int hoursRemaining;
if (hoursAvailable > 0) {
hoursRemaining = hoursAvailable - hoursNeeded;
if(hoursRemaining < 0) {
System.out.println(“Not enough time.”);
} else {
String suffix = “”;
if(hoursRemaining != 1) {
suffix = “s”;
}
System.out.println(“You will have “ + hoursRemaining + “ hour” + suffix + “ remaining.”);
}
} else {
System.out.println(“Times up.”);
}
You will have 0 hours remaining.
You will have 5 hours remaining.
Not enough time.
Times up.
You will have 1 hour remaining.
You will have 0 hours remaining.
Which property or method is used to get the number of elements in an array?
sizeof
lengthof
length
size
length
Which of the following will initialize the names array to be three elements?
▢ String[] names = new[3];
▢ String[] names = new String[3];
▢ String[] names = String * 3;
▢ String[] names = { “Steve”, “Mary”, “William” };
▢ String[] names = (1, 2, 3);
▢ String names = new String(“3”);
▢ String[] names = new[3];
√ String[] names = new String[3];
▢ String[] names = String * 3;
√ String[] names = { “Steve”, “Mary”, “William” };
▢ String[] names = (1, 2, 3);
▢ String names = new String(“3”);
Select the answer which describes the output of the following code.
int[] ages = {2, 37, 48, 3, 5};
System.out.println(ages[2] + “ “ + ages[1]);
37 48
48 37
37 2
48 3
2 37
48 37
Given the following loop code, what is the name of the array being iterated over?
for(int age : ages) {
…
}
age
for
ages
int
ages
Given the following loop code, how many iterations will be performed?
String[] numbers = { “2”, “3”, “4”, “5” };
for(String number : numbers) {
}
2
4
5
3
4
What is the break keyword used for?
Skip to the end of an if/else block
Raise an exception from within a loop
Skip to the end of a for loop
Skip the current iteration of a loop an proceed to the next
Skip to the end of a for loop
What are the two possible values of a boolean expression?
True
False
A ______ ________ is a combination of variables, values and operators that evaluate to true or false.
boolean expression
The following are examples of what?
==
!=
<
<=
>
>=
Relational Operators
An ____ is an indexed container that holds a set of values of a single type
array
Each item in an array is called an _______
element