Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class ArraysAreUseful {

    public static void main(String[] args) {
        int a[] = new int[10];
        for (int i = 0; i < a.length; i += 2) {
            a[i] = i * 2;
        }
        print(a);
        for (int i = 0; i < a.length; i += 3) {
            a[i] = i * 3;
        }
        print(a);
        int[] b = Arrays.copyOf(a, 10);
        Arrays.sort(b);
        print(b);
        Arrays.fill(a, 5, 7, 6);
        print(a);
        Arrays.fill(b, 5, 6, 6);
        print(b);
    }

    private static void print(int[] a) {
        for (int elem : a) {
            System.out.print((elem == 0 ? "." : elem) + ".");
        }
        System.out.println();
    }
}


....4...8...12...16...
....4.9.8...18...16.27.
........4.8.9.16.18.27.
....4.9.8.6.6...16.27.
........4.6.9.16.18.27.
2...6...10...14...18...
3...6.12.10...21...18.30.
......3.6.10.12.18.21.30.
3...6.12.10.6.6...18.30.
......3.6.6.12.18.21.30.
....4...8...12...16...
....4.9.8...18...16.27.
........4.8.9.16.18.27.
....4.9.8.6.6.6.6.6.
........4.6.6.6.6.6.
Compilation Error
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