Java sample questions and answers
Question
1
-
The
following pseudocode is an example of a(n) ____ structure:
get firstNumber get secondNumber add firstNumber and
secondNumber print result
Answer
Question
2
-
The
following pseudocode is an example of a(n) ____ structure:
if firstNumber is bigger than secondNumber then print
firstNumber else print secondNumber
Question
3
-
Fill in
the blank in the following pseudocode:if
someCondition is true then do oneProcess____ do
theOtherProcess
Question
4
-
The
following pseudocode is an example of a(n) ____ structure:
get number while number is positive add to
sum get number
Question
5
-
The
statement that best describes the following pseudocode is: ____.if
conditionA is true then do stepEelse do stepB if conditionF
is true then while conditionI is
true do stepJ endwhile
else do stepG endif do stepDendif
Answer
Question
6
-
The
following pseudocode reads a number from the user, multiplies it by 2 and
prints the result. The ____ program statement should replace the ? to make this
program functional and structured. get
inputNumber while not eof
calculatedAnswer = inputNumber * 2 print
calculatedAnswer ? endwhile
Question
7
-
Years ago,
programmers could avoid using structure by inserting a “____” statement into
their pseudocode.
Question
8
-
Structured
programs can be easily broken down into routines or ____ that can be assigned
to any number of programmers.
Question
9
-
The
following pseudocode might be rewritten using a(n) ____ structure:if
class = "Freshman" then tuitionFee = 75else if class =
"Sophomore" then tuitionFee = 50
else if class = "Junior"
then tuitionFee = 30
else tuitionFee = 10
endif endifendif
Question
10
-
____ is
the process of paying attention to important properties while ignoring
nonessential details.
Answer
Question
11
-
____ is
the feature of programs that assures you a module has been tested and proven to
function correctly.
Question
12
-
In a
flowchart, you draw each module separately with its own sentinel symbols. The
symbol that is the equivalent of the start symbol in a program contains the
____.
Question
13
-
When a
program or module uses another module, you can refer to the main program as the
____ program.
Question
14
-
The
computer keeps track of the correct memory address to which it should return
after executing a module by recording the memory address in a location known as
the ____.
Question
15
-
A variable
that is used known to the entire program is a ____ variable.
Question
16
-
When
declaring a variable in languages such as Visual Basic, C++, Java and C#, the
____ must be identified.
Question
17
-
The
structure that is used in a binary selection is ____.
Question
18
-
The
statement that best describes the following pseudocode is ____.if
hoursWorked > 40 then grossPay = 40 * rate + (hoursWorked
- 40) * 1.5 * rateelse grossPay = hoursWorked * rateendif
Answer
Question
19
-
Boolean
expressions are named after ____.
Answer
Question
20
-
The
decision structure that is logically equivalent to the following is ___.if
customerCode not equal to 1 then discount =
0.25else discount = 0.50endif
Answer
Question
21
-
Assume
that out of 1,000 salespeople, 900 sell more than three items in a pay period,
and only 500 sell items valued at $1000 or more. How many total questions must
be asked in the following pseudocode to evaluate bonuses for 1000 salespeople?if
itemsSold > 3 then if valueSold >= 1000
then bonusGiven =
BONUS endifendif
Question
22
-
For
maximum efficiency, a good rule of thumb in an OR decision is to ____.
Question
23
-
The symbol
that represents a logical OR in Perl, Java, C++, and C# is ____.
Question
24
-
The
logical AND
operator can be compared to ____ in terms of precedence.
Question
25
-
The
logical OR
operator can be compared to ____ in terms of precedence.
Question
26
-
The piece
of pseudocode that represents incrementing the loop control variable is ____.
Question
27
-
In the
following pseudocode fragment, the while loop will terminate when ____.
counter
= 10while response = ‘Y’
print
counter counter = counter - 1
print “Do you want to see the next counter? Y or N”
get
response
endwhile
Question
28
-
In the
following pseudocode, the statement print
questionCounter will be executed ____ times.num
PARTS = 5
num QUESTIONS = 3
partCounter = 1
while partCounter <=
PARTS
questionCounter = 1
while
questionCounter <=
QUESTIONS
print
questionCounter
questionCounter = questionCounter + 1
endwhile partCounter = partCounter + 1endwhile
Question
29
-
What is
wrong with the following? rep = 10 while (rep
< 20) print “error” endwhile
Question
30
-
In a for
loop, a(n) ____ value is used to control how the loop control variable is incremented.
Question
31
-
The
statement that is true of a structured loop is that ____.
Question
32
-
An array
is a(n) ____ of variables in memory.
Question
33
-
The number
of elements in an array is called the ____ of the array.
Question
34
-
All of the
elements in an array have the same ____.
Question
35
-
An array
can be used to replace ____.
Question
36
-
Another
name for a two dimensional array is a(n) ____.
Question
37
-
The
array that follows is an array ofdouble[]
grades = new double[3];
Question
38
-
Which
of the following is an invalid list of elements in an array?
Question
39
-
What
numbers does the code that follows print to the console?int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};for (int i = 0; i <
9; i++){ System.out.println(numbers[i]);}
Question
40
-
The
length of the array that follows isint[]
grades = new int[4];
Question
41
-
What
is the value of names[4] in the following array?String[] names = {"Jeff", "Dan",
"Sally", "Jill", "Allie"};
Question
42
-
What
is the value of times[2][1] in the array that follows?double[][] times = { {23.0, 3.5}, {22.4, 3.6}, {21.3, 3.7} };
Question
43
-
How
many rows are in the array that follows?Rental[][]
transactions = new Rental[7][3];
Question
44
-
What
is the value of nums[2] after the following statements are executed?int[] values = {2, 3, 5, 7, 9};int[] nums = values;values[2] = 1;
Question
45
-
Consider
the following condition. It will be true when(!(endProgram.equalsIgnoreCase("n")))
Question
46
-
Which
of the following statements do you use to jump to the top of an outer loop from
an inner loop?
Question
47
-
How
many lines are printed on the console when the following for loop is executed?for (int i = 2; i < 10; i++){
System.out.println(i);}
Question
48
-
How
many lines are printed on the console when the following for loop is executed?for (int j = 10; j < 40; j *= 2) {
System.out.println(j);}
Question
49
-
How
many lines are printed on the console when the following for loops are
executed?for (int i = 1; i <
5; i += 2){ for (int j = 0; j < i; j++)
{ System.out.println(j);
}}
Question
50
-
Assume
that the variable named entry has a starting value of 9 and number has a value
of 3. What is the value of entry after the following statements are executed?if ((entry > 9) || (entry/number == 3))
entry--;else if (entry == 9) entry++;else
entry = 3;
-------------------------------------------------------------
Answers:
|
|
|
The following pseudocode is an
example of a(n) ____ structure:
get firstNumber
get secondNumber
add firstNumber and secondNumber
print result
|
|
|
|
|
|
|
|
|
|
|
The following pseudocode is an
example of a(n) ____ structure:
if firstNumber is bigger than secondNumber then
print firstNumber
else
print secondNumber
|
|
|
|
|
|
|
|
|
|
|
Fill in the blank in the following
pseudocode:
if someCondition is true then
do oneProcess
____
do theOtherProcess
Answer
|
|
|
|
|
|
|
|
|
|
|
The following pseudocode is an
example of a(n) ____ structure:
get number
while number is positive
add to sum
get number
Answer
|
|
|
|
|
|
|
|
|
|
|
The statement that best describes
the following pseudocode is: ____.
if conditionA is true then
do stepE
else
do stepB
if conditionF is true then
while conditionI is true
do stepJ
endwhile
else
do stepG
endif
do stepD
endif
|
|
|
|
Answer:
|
A loop is nested in a decision
that is nested in another decision
|
|
|
|
|
2 out of 2
points
|
|
|
The following pseudocode reads a
number from the user, multiplies it by 2 and prints the result. The ____
program statement should replace the ? to make this program functional and
structured.
get inputNumber
while not eof
calculatedAnswer = inputNumber * 2
print calculatedAnswer
?
endwhile
Answer
|
|
|
|
|
|
|
|
|
|
|
Years ago, programmers could avoid
using structure by inserting a “____” statement into their pseudocode.
Answer
|
|
|
|
|
|
|
|
|
|
|
Structured programs can be easily
broken down into routines or ____ that can be assigned to any number of
programmers.
|
|
|
|
Answer: modules |
|
|
|
|
|
|
The following pseudocode might be
rewritten using a(n) ____ structure:
if class = "Freshman" then
tuitionFee = 75
else
if class = "Sophomore" then
tuitionFee = 50
else
if class = "Junior" then
tuitionFee = 30
else
tuitionFee = 10
endif
endif
endif
Answer
|
|
|
|
|
|
|
|
|
|
|
____ is the process of paying
attention to important properties while ignoring nonessential details.
Answer
|
|
|
|
|
|
|
|
|
|
|
____ is the feature of programs
that assures you a module has been tested and proven to function correctly.
Answer
|
|
|
|
|
|
|
|
|
|
|
In a flowchart, you draw each
module separately with its own sentinel symbols. The symbol that is the
equivalent of the start symbol in a program contains the ____.
Answer
|
|
|
|
|
|
|
|
|
|
|
When a program or module uses
another module, you can refer to the main program as the ____ program.
Answer
|
|
|
|
|
|
|
|
|
|
|
The computer keeps track of the
correct memory address to which it should return after executing a module by
recording the memory address in a location known as the ____.
Answer
|
|
|
|
|
|
|
|
|
|
|
A variable that is used known to
the entire program is a ____ variable.
Answer
|
|
|
|
|
|
|
|
|
|
|
When declaring a variable in
languages such as Visual Basic, C++, Java and C#, the ____ must be
identified.
Answer
|
|
|
|
|
variable name and data type
|
|
|
|
|
|
|
|
The structure that is used in a
binary selection is ____.
Answer
|
|
|
|
|
|
|
|
|
|
|
The statement that best describes
the following pseudocode is ____.
if hoursWorked > 40 then
grossPay = 40 * rate + (hoursWorked - 40) * 1.5 * rate
else
grossPay = hoursWorked * rate
endif
Answer
|
|
|
|
|
dual-alternative selection
|
|
|
|
|
2 out of 2
points
|
|
|
Boolean expressions are named
after ____.
Answer
|
|
|
|
|
|
|
|
|
|
|
The decision structure that is
logically equivalent to the following is ___.
if customerCode not equal to 1 then
discount = 0.25
else
discount = 0.50
endif
Answer
|
|
|
|
|
if customerCode = 1 then
discount = 0.50
else
discount = 0.25
endif
|
|
|
|
|
|
|
|
Assume that out of 1,000
salespeople, 900 sell more than three items in a pay period, and only 500
sell items valued at $1000 or more. How many total questions must be asked in
the following pseudocode to evaluate bonuses for 1000 salespeople?
if itemsSold > 3 then
if valueSold >= 1000 then
bonusGiven = BONUS
endif
endif
Answer
|
|
|
|
|
|
|
|
|
|
|
For maximum efficiency, a good
rule of thumb in an OR
decision is to ____.
|
|
|
|
Answer:
|
first ask the question that is
more likely to be true
|
|
|
|
|
|
|
|
The symbol that represents a
logical OR
in Perl, Java, C++, and C# is ____.
Answer
|
|
|
|
|
|
|
|
|
|
|
The logical AND operator can be compared to ____
in terms of precedence.
|
|
|
|
|
|
|
|
|
|
|
The logical OR operator can be compared to ____
in terms of precedence.
|
|
|
|
|
|
|
|
2 out of 2
points
|
|
|
The piece of pseudocode that
represents incrementing the loop control variable is ____.
|
|
|
|
|
|
|
|
|
|
|
In the following pseudocode
fragment, the while loop will terminate when ____.
counter = 10
while response = ‘Y’
print counter
counter = counter - 1
print “Do you want to see the next counter? Y or N”
get response
endwhile
|
|
|
|
|
|
|
|
|
|
|
In the following pseudocode, the
statement print questionCounter will be executed ____ times.
num PARTS = 5
num QUESTIONS = 3
partCounter = 1
while partCounter <= PARTS
questionCounter = 1
while questionCounter <= QUESTIONS
print questionCounter
questionCounter =
questionCounter + 1
endwhile
partCounter = partCounter + 1
endwhile
|
|
|
|
|
|
|
|
|
|
|
What is wrong with the following?
rep = 10
while (rep < 20)
print “error”
endwhile
|
|
|
|
Answer:
|
loop control variable is not
altered
|
|
|
|
|
|
|
|
In a for loop, a(n) ____ value is
used to control how the loop control variable is incremented.
|
|
|
|
|
|
|
|
|
|
|
The statement that is true of a
structured loop is that ____.
|
|
|
|
Answer:
|
the
loop condition represents the only exit from the loop
|
|
|
|
|
|
|
|
An array is a(n) ____ of variables
in memory.
Answer
|
|
|
|
|
|
|
|
2 out of 2
points
|
|
|
The number of elements in an array
is called the ____ of the array.
|
|
|
|
|
|
|
|
|
|
|
All of the elements in an array
have the same ____.
|
|
|
|
|
|
|
|
|
|
|
An array can be used to replace
____.
|
|
|
|
|
|
|
|
|
|
|
Another name for a two dimensional
array is a(n) ____.
|
|
|
|
|
|
|
|
|
|
|
The array that follows
is an array of
double[] grades = new double[3];
|
|
|
|
|
|
|
|
|
|
|
Which of the following
is an invalid list of elements in an array?
|
|
|
|
|
|
|
|
|
|
|
What numbers does the
code that follows print to the console?
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i < 9; i++)
{
System.out.println(numbers[i]);
}
|
|
|
|
|
|
|
|
|
|
|
The length of the
array that follows is
int[] grades = new int[4];
|
|
|
|
|
|
|
|
|
|
|
What is the value of
names[4] in the following array?
String[] names = {"Jeff",
"Dan", "Sally", "Jill", "Allie"};
|
|
|
|
|
|
|
|
|
|
|
What is the value of
times[2][1] in the array that follows?
double[][] times = { {23.0, 3.5}, {22.4, 3.6},
{21.3, 3.7} };
|
|
|
|
|
|
|
|
|
|
|
How many rows are in
the array that follows?
Rental[][] transactions = new Rental[7][3];
|
|
|
|
|
|
|
|
|
|
|
What is the value of
nums[2] after the following statements are executed?
int[] values = {2, 3, 5, 7, 9};
int[] nums = values;
values[2] = 1;
|
|
|
|
|
|
|
|
|
|
|
Consider the following
condition. It will be true when
(!(endProgram.equalsIgnoreCase("n")))
|
|
|
|
Answer:
|
the value of
endProgram doesn’t equal “n” or “N”
|
|
|
|
|
|
|
|
Which of the following
statements do you use to jump to the top of an outer loop from an inner loop?
|
|
|
|
|
|
|
|
|
|
|
How many lines are
printed on the console when the following for loop is executed?
for (int i = 2; i < 10; i++)
{
System.out.println(i);
}
|
|
|
|
|
|
|
|
|
|
|
How many lines are
printed on the console when the following for loop is executed?
for (int j = 10; j < 40; j *= 2)
{
System.out.println(j);
}
|
|
|
|
|
|
|
|
|
|
|
Assume that the
variable named entry has a starting value of 9 and number has a value of 3.
What is the value of entry after the following statements are executed?
if ((entry > 9) || (entry/number == 3))
entry--;
else if (entry == 9)
entry++;
else
entry = 3;
|
|
|
|
|
|
|
|