Question: 1-Which loop statement outputs the elements of array a? a. for(int i = 0; true; i++) System.out.println(a[i]); b. for(int i = 0; true; i++) ;

1-Which loop statement outputs the elements of array a?

a. for(int i = 0; true; i++) System.out.println(a[i]); b. for(int i = 0; true; i++) ; System.out.println(a[i]); c. for(int i = 0; i <= a.length; i++) System.out.println(a[i]); d. for(int i = 1; i <= a.length ; i++) System.out.println(a[i-1]); e. None of the above

2-Which if statement on the right should be used inside the for loop to check for the odd elements in array a?for(int i = 0; i < a.length; i++) a. if(a[i] % 2 = 1) b. if(a[i] % 2 != 1) c. if(i%2 == 1) d. if(a[i] % 2 == 1) e. None of the above

3-To check if the last element in an integer array a is even we write :

a. if(a[i-n] % 2 == 0) b. if(a[n-1] % 2 == 0) f. if(a[a.length-i] % 2 == 0) g. if(a[a.length-1] % 2 == 0) h. None of the above

4-To define a method checkNumber to check and return if a given integer is odd or not, we write the header as :

a. public static boolean checkNumber(integer x) b. public static int checkNumber(integer x) c. public static int checkNumber(int x) d. public static void checkNumber(int x) e. None of the above

5-Which of the following loops is infinite?

a. for(int i = 0; true ; i++) b. for(int i = 0; i < Math.pow(2,32); i++) c. Both a. & b.

d.None of the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!