@@ -0,0 +1,1023 @@
+public class Solution %7B%0A    public static int firstOccurrence(int%5B%5D nums, int k) %7B%0A        int first = 0;%0A        int last = nums.length - 1;%0A        while (first %3C last - 1) %7B%0A            int med = first + (last - first) / 2;%0A            if (nums%5Bmed%5D %3C k) %7B%0A                first = med;%0A            %7D else %7B%0A                last = med;%0A            %7D%0A        %7D%0A        if (nums%5Bfirst%5D == k) return first;%0A        else if (nums%5Blast%5D == k) return last;%0A        else return -1;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D nums = %7B 1, 1, 1, 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 8, 10, 10, 11, 12, 16 %7D;%0A        System.out.print(%22Array: %5B%22);%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            System.out.print(nums%5Bi%5D);%0A            if (i != nums.length - 1) System.out.print(%22, %22);%0A        %7D%0A        System.out.println(%22%5D%22);%0A        for (int k = 0; k %3C 20; k++) %7B%0A            int first = firstOccurrence(nums, k);%0A            System.out.println(k + %22 first found at index %22 + first);%0A        %7D%0A    %7D%0A%7D%0A

Write solution to question 1 in java