My Report

Java Array Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following Java code?

 
    class array_output 
    {
        public static void main(String args[]) 
        {
            int array_variable [] = new int[10];
	    for (int i = 0; i < 10; ++i) 
            {
                array_variable[i] = i;
                System.out.print(array_variable[i] + " ");
                i++;
            }
        } 
    }

2. What will be the output of the following Java code?

    int arr[] = new int [5];
    System.out.print(arr);

3. What will be the output of the following Java code?

 
    class array_output 
    {
        public static void main(String args[]) 
        {
            int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
            int sum = 0;
            for (int i = 0; i < 3; ++i)
                for (int j = 0; j <  3 ; ++j)
                    sum = sum + array_variable[i][j];
            System.out.print(sum / 5);
        } 
    }

4. Which of these is necessary to specify at time of array initialization?

5. Which of these is an incorrect Statement?

6. Which of these operators is used to allocate memory to array variable in Java?

7. What will be the output of the following Java code?

 
    class multidimention_array 
    {
        public static void main(String args[])
        {
            int arr[][] = new int[3][];
            arr[0] = new int[1];
            arr[1] = new int[2];
            arr[2] = new int[3];               
	    int sum = 0;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    arr[i][j] = j + 1;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    sum + = arr[i][j];
	    System.out.print(sum); 	
        } 
    }

8. Which of these is an incorrect array declaration?

9. What will be the output of the following Java code?

 
    class array_output 
    {
        public static void main(String args[]) 
        {
            char array_variable [] = new char[10];
	    for (int i = 0; i < 10; ++i) 
            {
                array_variable[i] = 'i';
                System.out.print(array_variable[i] + "");
            }
        } 
    }

10. What will be the output of the following Java code?

 
    class evaluate 
    {
        public static void main(String args[]) 
            {
	        int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
	        int n = 6;
                n = arr[arr[n] / 2];
	        System.out.println(arr[n] / 2);
            } 
    }

 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.