exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 9 discussion

Actual exam question from Oracle's 1z0-809
Question #: 9
Topic #: 1
[All 1z0-809 Questions]

Given:
class Sum extends RecursiveAction { //line n1 static final int THRESHOLD_SIZE = 3; int stIndex, lstIndex; int [ ] data; public Sum (int [ ]data, int start, int end) { this.data = data; this stIndex = start; this. lstIndex = end;
}
protected void compute ( ) {
int sum = 0;
if (lstIndex "" stIndex <= THRESHOLD_SIZE) {
for (int i = stIndex; i < lstIndex; i++) {
sum += data [i];
}
System.out.println(sum);
} else {
new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );
new Sum (data, stIndex,
Math.min (lstIndex, stIndex + THRESHOLD_SIZE)
).compute ();
}
}
}
and the code fragment:
ForkJoinPool fjPool = new ForkJoinPool ( );
int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
fjPool.invoke (new Sum (data, 0, data.length));
and given that the sum of all integers from 1 to 10 is 55.
Which statement is true?

  • A. The program prints several values that total 55.
  • B. The program prints 55.
  • C. A compilation error occurs at line n1.
  • D. The program prints nothing.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Ritesh_
Highly Voted 4 years, 9 months ago
Answer is A
upvoted 5 times
...
asdfjhfgjuaDCV
Most Recent 5 months ago
A is the correct answer
upvoted 1 times
...
Svetleto13
3 years, 1 month ago
Answer is A,but if we do little change to this: if (lstIndex - stIndex >= THRESHOLD_SIZE) answer is B.
upvoted 1 times
mevlt
2 years, 4 months ago
If you use (lstIndex - stIndex >= THRESHOLD_SIZE) then you will not get the benefit of using parallel tasking which is the point of RecursiveAction and RecursiveTask.
upvoted 1 times
...
...
Pasci
4 years, 1 month ago
if (lstIndex - stIndex <= THRESHOLD_SIZE)
upvoted 3 times
...
Innovation
4 years, 6 months ago
A is correct, tested
upvoted 1 times
...
M_Jawad
4 years, 6 months ago
A is the correct answer
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago