Menu
Question Index
...

What will be 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
-3
22 18 16 14 12 10 8 6 4 2
0 2 4 6 8 10 12 14 16 18
-3
22 2 12 6 8 10 4 14 18 0  
0 2 4 6 8 10 12 14 16 18
-2
22 2 12 6 8 10 4 18 0 22
Some other output
Compilation Error 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