exam questions

Exam 98-388 All Questions

View all questions & answers for the 98-388 exam

Exam 98-388 topic 1 question 27 discussion

Actual exam question from Microsoft's 98-388
Question #: 27
Topic #: 1
[All 98-388 Questions]

HOTSPOT -
You work as an intern Java programmer at Adventure Works. Your team lead asks you to create a method.
The method must meet the following requirements:
✑ Accept an int array
✑ Check for duplicate values in the array
✑ Stop the outer loop as soon as a duplicate value has been detected and return true
✑ Return false if all values in the array are unique
How should you complete the code? To answer, select the appropriate code segments in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
References:
https://stackoverflow.com/questions/3951547/java-array-finding-duplicates

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
BiDzej
Highly Voted 4 years, 8 months ago
int x = 0; x < array.length - 1; //x has to be max one before last element as y in next loop is x+1 and we are targeting element at index y, else there would be out of index exception y++ break;
upvoted 10 times
Abhitera
4 years, 4 months ago
Correct
upvoted 1 times
Walkie
3 years, 1 month ago
Shouldn't it be x<= array.length-1 so that the last element in the array can be accessed?
upvoted 1 times
...
...
...
mtmoore
Highly Voted 4 years, 9 months ago
The third part should be y++.
upvoted 8 times
...
lulzosad
Most Recent 3 years, 12 months ago
boolean isDuplicate = false; for(int x = 0; x <= array.length - 1; x++) { for(int y = x + 1; y < array.length; y++) if(array[x] == array[y]) isDuplicate = true; if(isDuplicate) break; } return isDuplicate;
upvoted 2 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 ...