What is the output of the following when run as java unix.MyClass seed flower?
package unix; //from www . j a va 2 s .c o m import java.util.*; public class MyClass { ? public static void main(String[] args) { String one = args[0]; Arrays.sort(args); int result = Arrays.binarySearch(args, one); System.out.println(result); } }
B.
This class is called with two arguments.
The first one (seed) is stored in the variable one.
Then the array is sorted, meeting the precondition for binary search.
Binary search returns 1 because seed is the second element in the sorted array, and Java uses zero-based indexes.
Option B is correct.