Sorting

AP Computer Science A· difficulty 2/5

int[] a = {7, 3, 9, 1, 5};
java.util.Arrays.sort(a);
int median = a[a.length / 2];

What is median?

  • A

    3

  • B

    9

  • C

    5

    check_circle
  • D

    7

Explanation

Sorted: {1,3,5,7,9}; index 2 is 5, the median.

Want 10 more like this — adaptive to your weak spots?

Related questions