Accenture Primer
Accenture DumpmediumAccenture PrimerPrimer-Dump

Accenture Accenture Primer Practice Question

import java.util.*; public class Main {

Answer options

A
public static void main(String[] args)
B
String[] str={"Banana","Apple","Watermelon","Mango"};
C
sortFruit o=new sortFruit();
D
Arrays.sort(str,o);
E
for(String s: str)
F
System.out.print(s+" ");
G
System.out.println(Arrays.binarySearch(str,"map"));
H
static class sortFruit implements Comparator<String>
I
public int compare(String str1,String str2)
J
return str2.compareTo(str1);

Correct answer: return str2.compareTo(str1);

Explanation

sortFruit reverses the natural order (return str2.compareTo(str1)). Sorted descending: Watermelon, Mango, Banana, Apple. Arrays.binarySearch on a reverse-sorted array with key 'map' returns a negative index (implementation-defined, shown as -5). Output: 'Watermelon Mango Banana Apple -5'. Option 9 (return str2.compareTo(str1)) is the key comparator logic.

Related Accenture Accenture Primer questions

Practice more Accenture Accenture Primer questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.