Menu
Topics Index
...
`

Arrays


If you need explanation Read this topic

If you need Answer Take test on this topic

Arrays
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();
    }
}

A. 0 2 4 6 8 10 12 14 16 18 
-1
18 2 12 6 8 10 4 16 0 2
B. 0 2 4 6 8 10 12 14 16 18 
-3
22 2 12 6 8 10 4 16 0 22
C. 0 2 4 6 8 10 12 14 16 18 
-1
22 2 12 6 8 10 4 16 0 14
D. 0 2 4 6 8 10 12 14 16 18 
-3
22 2 12 6 8 10 4 18 0 22 
E. 0 2 4 6 8 10 12 14 16 18 
-3
18 22 12 6 8 10 4 16 0 22
F. Compilation or Runtime Error
Topic: java.util.Arrays - Class Arrays In Collection Framework

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

D ans..as the first row displays the first row as even integers upto 18 and it do inserrt n then binary search ...later on create a temp array and print it out....

Posted by Sai Abhishek    2014-03-11 13:28:06


ans is D initially array consists of 0,2,4...18
dey r printed fill func replaces 7,8 indexes to 22 as search is unsuccessful it returns -2-1=-3 nd prints -3 in temparray values stored are 0,4,8,12,22 nd dese values are agn assigned to array 22 is stored in 0th place 12 in 2 8 in 4th and so on

Posted by Teja Potlapally    2014-03-11 13:30:32


Congratulations Teja Potlapally. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-12 04:25:06


© meritcampus 2019

All Rights Reserved.

Open In App