Menu
Question Index
...

What is the output of the following program?

import java.util.*;

public class Google {
    public static void main(String[] args) {
        int[] array = new int[10];
        for (int i = 0; i < 10; i++) { array[i] = 2 * i;   }
        dispay(array);
        Arrays.fill(array, 7, 9, 22);
        Arrays.sort(array);
        int foundAt = Arrays.binarySearch(array, 0, 5, 3);
        System.out.println(foundAt);
        int temp = 0;
        int tempArray[] = new int[array.length / 2 + 1];
        for (int i = 0; i < array.length; i = i + 2) { tempArray[temp++] = array[i]; }
        Arrays.sort(array);
        for (int i = 0; i < array.length; i = i + 2) { array[i] = tempArray[--temp]; }
        dispay(array);
    }

    private static void dispay(int[] array) {
        for (int in : array) { System.out.print(in + " "); }
        System.out.println();
    }
}


0 2 4 6 8 10 12 14 16 18
-1
18 2 12 6 8 10 4 16 0 2
0 2 4 6 8 10 12 14 16 18
-3
22 2 12 6 8 10 4 16 0 22
0 2 4 6 8 10 12 14 16 18
-1
22 2 12 6 8 10 4 16 0 14
0 2 4 6 8 10 12 14 16 18
-3
22 2 12 6 8 10 4 18 0 22
0 2 4 6 8 10 12 14 16 18
-3
18 22 12 6 8 10 4 16 0 22
Compilation or Runtime Error

Doubts

Problems

Topic: java.util.Arrays - Class Arrays In Collection Framework

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App