Question discussion

What is the output of the following Java program?import java.util.*; public class Main { public static void main(String[] args) { int[] a =…

1113Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Java program?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        int[] a = {3, 1, 2};
        Arrays.sort(a);
        System.out.println(Arrays.toString(a) + a.length);
    }
}
  • A[3, 1, 2]3
  • B[1, 2, 3]2
  • C[1, 2, 3]3
  • DCompilation error
Correct answer: C

Explanation

Arrays.sort sorts in place giving [1, 2, 3]; the string concatenation then appends the length 3 with no space.

Discussion 0

Nobody has replied yet. Start the discussion!