Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with answering some questions for Java Programing: (1) Which of

ID: 3805551 • Letter: I

Question

I need some help with answering some questions for Java Programing:

(1)     Which of the following declares an array of int named hits?

            (a)        int hits;                (b)        new int hits[];

            (c)        int[] hits;           (d)        int hits = int[]

            int[] array1 = { 1, 3, 5, 7 }

           

           for(int i = 0; i < array.length; i++) {

           if(array1[i] > 5)

               System.out.println(i + " " + array1[i]);

           }

(2)     Which indices are in bounds for the array array1, given the declaration above?

            (a)        0 , 1 , 2 , 3                      (b)        1 , 3 , 5 , 7

(c)        1 , 2 , 3 , 4                      (d)        0 , 1 , 3 , 5

(3)     What is the output of the code fragment above?

            (a)        0 3                               (b)        7 3

            (c)        3 7                               (d)        5 1

int[] x = new int[10];

x[0] = 34;

x[1] = 88;

System.out.println(x[0] + " " + x[1] + " " + x[10]);

(4)     What is the output of the code fragment above?

(a)        34 88 0                       (b)        0 34 88   

            (c)        34 88 88                      (d)        This program throws an exception.

(5)     A " matrix " is a two - dimensional array.

(a)     True        (b)     False

(6)     The following declaration int[ ][ ] senators = new int[50][2]; is an      example of a " multidimensional array. "

(a)     True        (b)     False   

(7)     Given an array score[x] " x " can be referred to as either the " index " or " subscript "     of the array.

(a)     True        (b)     False

(8)     The following is a legal array declaration: int[ ] intArray = new int[ ];

(a)     True        (b)     False

Explanation / Answer

(1)     Which of the following declares an array of int named hits?

Answer: (c)        int[] hits;

(2)     Which indices are in bounds for the array array1, given the declaration above?

Answer: (a)        0 , 1 , 2 , 3

(3)     What is the output of the code fragment above?

Answer:(c)        3 7

(4)     What is the output of the code fragment above?

Answer: (a)        34 88 0

(5)     A " matrix " is a two - dimensional array.

Answer: a) True

(6)     The following declaration int[ ][ ] senators = new int[50][2]; is an      example of a " multidimensional array. "

Answer: (a)     True

(7)     Given an array score[x] " x " can be referred to as either the " index " or " subscript "     of the array.

Answer: a) True

(8)     The following is a legal array declaration: int[ ] intArray = new int[ ];

Answer: a) True

Array declaration should be int[ ] intArray = new int[10 ];