Sunday, December 9, 2012

Java question & answer


Java sample questions and answersDescription: Expand
Question 1
  1.  
The following pseudocode is an example of a(n) ____ structure:  get firstNumber  get secondNumber  add firstNumber and secondNumber  print result
Answer
sequence
decision
loop
nested

Question 2
  1.  
The following pseudocode is an example of a(n) ____ structure:  if firstNumber is bigger than secondNumber then    print firstNumber  else    print secondNumber

sequence
decision
loop
nested
  
Question 3
  1.  
Fill in the blank in the following pseudocode:if someCondition is true then   do oneProcess____   do theOtherProcess

then
while
do
else



Question 4
  1.  
The following pseudocode is an example of a(n) ____ structure:  get number  while number is positive    add to sum    get number

sequence
decision
loop
nested
Question 5
  1.  
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
A decision is nested in a sequence
A decision is nested in a loop
A loop is nested in a decision that is nested in another decision
A sequence is nested inside a decision nested in another decision

Question 6
  1.  
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
no statement is needed
if done then exit
get inputNumber
print inputNumber

Question 7
  1.  
Years ago, programmers could avoid using structure by inserting a “____” statement into their pseudocode.

loop
go next
next
go to

Question 8
  1.  
Structured programs can be easily broken down into routines or ____ that can be assigned to any number of programmers.

segments
modules
units
sequences
 
Question 9
  1.  
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

if-then-else
case
while
do while

Question 10
  1.  
____ is the process of paying attention to important properties while ignoring nonessential details.
Answer
Abstraction
Modularization
Reusability
Direction
 
Question 11
  1.  
____ is the feature of programs that assures you a module has been tested and proven to function correctly.

Modularization
Abstraction
Reliability
Reusability

Question 12
  1.  
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 ____.

id of the module
name of the module
description of the module
name of the program

Question 13
  1.  
When a program or module uses another module, you can refer to the main program as the ____ program.

director
calling
called
parent
Question 14
  1.  
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 ____.

flowchart
pointer
stack
set

Question 15
  1.  
A variable that is used known to the entire program is a ____ variable.

local
shared
non-modular
global

Question 16
  1.  
When declaring a variable in languages such as Visual Basic, C++, Java and C#, the ____ must be identified.

variable name only
variable data type only
variable name and data type
variable name, data type, and purpose

Question 17
  1.  
The structure that is used in a binary selection is ____.

if-then
if-then-else
while
do-while

Question 18
  1.  
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
dual-alternative selection
unary selection
case structure
if-then structure

Question 19
  1.  
Boolean expressions are named after ____.
Answer
Harold Boolean
Henry Boole
George Boole
Gerhardt Boolean
Question 20
  1.  
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
if customerCode > 1 then    discount = 0.50else    discount = 0.25 endif
if customerCode < 1 then    discount = 0.50else    discount = 0.25 endif
if customerCode = 1 then    discount = 0.50else    discount = 0.25 endif
if customerCode = 1 then    discount = 0.20else    discount = 0.50 endif
Question 21
  1.  
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
100
900
1000
1900

Question 22
  1.  
For maximum efficiency, a good rule of thumb in an OR decision is to ____.

first ask the question that is more likely to be true
first ask the question that is more likely to be false
rewrite as an and decision and ask the question more likely to be true
rewrite as an and decision and ask the question more likely to be false

Question 23
  1.  
The symbol that represents a logical OR in Perl, Java, C++, and C# is ____.

%
$
||
^

Question 24
  1.  
The logical AND operator can be compared to ____ in terms of precedence.

addition
subtraction
multiplication
division

Question 25
  1.  
The logical OR operator can be compared to ____ in terms of precedence.

addition
subtraction
multiplication
division

Question 26
  1.  
The piece of pseudocode that represents incrementing the loop control variable is ____.

rep = 1
rep = rep + 1
while (rep < 5)
print “warning”
 
Question 27
  1.  
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

counter = 0
the while loop will not terminate.
response = ‘Y’
response = ‘N’

Question 28
  1.  
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

0
3
5
15
Question 29
  1.  
What is wrong with the following?  rep = 10  while (rep < 20)    print “error”  endwhile
loop control variable is not initialized
loop control variable is not altered
loop control variable is not declared
loop body is missing

Question 30
  1.  
In a for loop, a(n) ____ value is used to control how the loop control variable is incremented.
step
group
id
sentinel
Question 31
  1.  
The statement that is true of a structured loop is that ____.
the loop can exit from any point
the loop body must execute at least once
the loop condition represents the only exit from the loop
the loop can repeat an infinite number of times
 
Question 32
  1.  
An array is a(n) ____ of variables in memory.
list
accumulation
set
record
 
Question 33
  1.  
The number of elements in an array is called the ____ of the array.
width
size
height
depth
Question 34
  1.  
All of the elements in an array have the same ____.
subscript
name
memory location
value
 
Question 35
  1.  
An array can be used to replace ____.
records
methods
nested decisions
loops
Question 36
  1.  
Another name for a two dimensional  array is a(n) ____.
vector
table
collection
set
Question 37
  1.  
The array that follows is an array ofdouble[] grades = new double[3];
grades
doubles
objects
arrays
 
Question 38
  1.  
Which of the following is an invalid list of elements in an array?
"Joe", "Doug", "Anne"
"Joe", 3, 25.5
3, 17, 12
12.3, 32.6, 21.7
  
Question 39
  1.  
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]);}
0-9
1-9
1-8
0-8
0-9
   
Question 40
  1.  
The length of the array that follows isint[] grades = new int[4];
0
3
4
5
  
Question 41
  1.  
What is the value of names[4] in the following array?String[] names = {"Jeff", "Dan", "Sally", "Jill", "Allie"};
Sally
Jill
Allie
name[4] doesn’t exist
 
Question 42
  1.  
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} };
 
3.7
22.4
3.5
21.3
3.6
 
Question 43
  1.  
How many rows are in the array that follows?Rental[][] transactions = new Rental[7][3];
7
6
3
2
  
Question 44
  1.  
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;
3
1
5
0
Question 45
  1.  
Consider the following condition. It will be true when(!(endProgram.equalsIgnoreCase("n")))
the value of endProgram equals “n”
the value of end Program equals “n” or “N”
the value of endProgram doesn’t equal “n”
the value of endProgram doesn’t equal “n” or “N”
 
Question 46
  1.  
Which of the following statements do you use to jump to the top of an outer loop from an inner loop?
continue
labeled continue
break
labeled break
Question 47
  1.  
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);}
8
9
10
7
   
Question 48
  1.  
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);}
1
2
3
4
 
Question 49
  1.  
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);    }}
2
4
5
20
Question 50
  1.  
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;
3
8
9
10
 
 -------------------------------------------------------------
Answers:






  • Question 1

The following pseudocode is an example of a(n) ____ structure:
  get firstNumber
  get secondNumber
  add firstNumber and secondNumber
  print result
 Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
sequence
  • Question 2

The following pseudocode is an example of a(n) ____ structure:
  if firstNumber is bigger than secondNumber then
    print firstNumber
  else
    print secondNumber
 
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
decision
  • Question 3

Fill in the blank in the following pseudocode:
if someCondition is true then
   do oneProcess
____
   do theOtherProcess
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
else
  • Question 4

The following pseudocode is an example of a(n) ____ structure:
  get number
  while number is positive
    add to sum
    get number
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
loop
  • Question 5

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:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
A loop is nested in a decision that is nested in another decision
  • Question 6
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
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
get inputNumber
  • Question 7

Years ago, programmers could avoid using structure by inserting a “____” statement into their pseudocode.
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
go to
  • Question 8

Structured programs can be easily broken down into routines or ____ that can be assigned to any number of programmers.
 
Answer: modules
  • Question 9


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
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
case
  • Question 10

____ is the process of paying attention to important properties while ignoring nonessential details.
Answer
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
Abstraction
  • Question 11

____ is the feature of programs that assures you a module has been tested and proven to function correctly.
Answer
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
Reliability
  • 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 ____.
Answer
 :
Description: https://blackboard.stlcc.edu/images/spacer.gif  
name of the module
  • Question 13

When a program or module uses another module, you can refer to the main program as the ____ program.
Answer
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
calling
  • 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 ____.
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
stack
 

A variable that is used known to the entire program is a ____ variable.
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
global
  • Question 16

When declaring a variable in languages such as Visual Basic, C++, Java and C#, the ____ must be identified.
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
variable name and data type
  • Question 17

The structure that is used in a binary selection is ____.
Answer
 
Description: https://blackboard.stlcc.edu/images/spacer.gif  
if-then-else
  • Question 18

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
  • Question 19
2 out of 2 points

Boolean expressions are named after ____.
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
George Boole
  • Question 20

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
Description: https://blackboard.stlcc.edu/images/spacer.gif  
if customerCode = 1 then
    discount = 0.50
else
    discount = 0.25
endif
  • 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
     endif
endif
Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
1900
  • Question 22

For maximum efficiency, a good rule of thumb in an OR decision is to ____.
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
first ask the question that is more likely to be true
  • Question 23
Description: https://blackboard.stlcc.edu/images/spacer.gif

The symbol that represents a logical OR in Perl, Java, C++, and C# is ____.
Answer
:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
||
  • Question 24


The logical AND operator can be compared to ____ in terms of precedence.
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
multiplication
  • Question 25

The logical OR operator can be compared to ____ in terms of precedence.
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
addition
  • Question 26
2 out of 2 points

The piece of pseudocode that represents incrementing the loop control variable is ____.
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
rep = rep + 1
  • Question 27

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
 Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
response = ‘N’
  • 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 + 1
endwhile
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
15
  • Question 29

What is wrong with the following?
  rep = 10
  while (rep < 20)
    print “error”
  endwhile
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
loop control variable is not altered
  • Question 30

In a for loop, a(n) ____ value is used to control how the loop control variable is incremented.
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
step
  • Question 31


The statement that is true of a structured loop is that ____.
 Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
the loop condition represents the only exit from the loop
  • Question 32

An array is a(n) ____ of variables in memory.
Answer
 Answer
Description: https://blackboard.stlcc.edu/images/spacer.gif  
list
  • Question 33
2 out of 2 points

The number of elements in an array is called the ____ of the array.
 
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
size
  • Question 34


All of the elements in an array have the same ____.
 Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
name
  • Question 35

An array can be used to replace ____.
 
Answer:
nested decisions
  • Question 36

Another name for a two dimensional  array is a(n) ____.
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
table
  • Question 37

The array that follows is an array of
double[] grades = new double[3];
 
 Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
doubles
  • Question 38

Which of the following is an invalid list of elements in an array?
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
"Joe", 3, 25.5
  • 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]);
}
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
1-9
  • Question 40

The length of the array that follows is
int[] grades = new int[4];
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
4
  • Question 41

What is the value of names[4] in the following array?
String[] names = {"Jeff", "Dan", "Sally", "Jill", "Allie"};
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
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} };
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
3.7
  • Question 43

How many rows are in the array that follows?
Rental[][] transactions = new Rental[7][3];
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
7
  • 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;
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
1
  • Question 45

Consider the following condition. It will be true when
(!(endProgram.equalsIgnoreCase("n")))
Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
the value of endProgram doesn’t equal “n” or “N”
  • Question 46

Which of the following statements do you use to jump to the top of an outer loop from an inner loop?
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
labeled continue
  • 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);
}
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
8
  • 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);
}
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
2
  • Question 49
 
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
4
  • 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;
  Answer:
Description: https://blackboard.stlcc.edu/images/spacer.gif  
8


Bottom of Form

No comments:

Post a Comment