Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arrays review.

Similar presentations


Presentation on theme: "Arrays review."— Presentation transcript:

1 Arrays review

2 What is the value of gem[1]? Int[] gem ; { -102, 14, 5, 100, -100};

3 What is the value of g after the call to nerdstuff?
Int[] stk = (1, 5, 19, 2, 20, 180}; Int g = nerdStuff(stk) + 1; Public static int nerdStuff(int[] cb) { Int counter = 0; For(int k =0; k<cb.length;++k) if (cb[k]<3) ++counter; return counter; } 3 2 7 None of these 3

4 Which of the following lines of code is a proper way to declare and initialize the c array?
Int[] c = mew omt[] { }; Int[10] c = { }; Int c = {1, 2, 3, 4}; Int[] c + new int {1, 2, 3, 4}; Both A and B a

5 What should replace <
What should replace <*1> in the code below in order that the for-loop var, j, would cycle through all indices of the array? Pubic static void testLoop(int[]a) { for(int j=0;<*1>;++j) ++a[j]; } J < a.length – 1 J < a.length() J <= a.length J < a.length + 1 None of these none

6 If <*1> has been filled in correctly in the code below, and a[3] = 19 before calling testLoop, what is a[3] afterwards? Pubic static void testLoop(int[]a) { for(int j=0;<*1>;++j) ++a[j]; } 3 19 18 20 None of these d

7 What is the output of the following code?
Public class ArrayTest { public static void main(String[] args) { String s1 = “abcdefghijk”; char[]x = s1.tocharArray(); String s2 = “mnopqrstuvw”; char[]y = s2.tocharArray(); int vv[] = {0,1,0,1}; for(intj=o;j<vv.length;j++) { switch(vv[j]) { case 0: System.out.print(x[j]); break; case 1: System.out..print(y[j+1]); } Ancp Mbod Aocq Abcd None of these c

8 What is output of the following code?
Public class ArrayTest { public static void main(String[] args){ int a[] = {0, 1, 2, 3}; int b[] = a; int sum = 0; for(int j=0;j<3;j++) { sum+=(a[j+1]*b[j]*b[j+1]); } System.out.println(sum); 14 15 16 Throws an exception None of these c

9 What is output of the following code?
Public class ArrayTest { public static void main(String[]args) { int[] z1={2,3,4,5,6}; int[] z2={1,2,1,2,1}; double d = 0; for(int j=0;j<3;j++) { d = d + Math.pow(z1[j+1],2) + Math.pow(z2[j],2); } System.out.println(d); 102 44 56 Throws and exception None of these c

10 What is output of the following code?
Public class MyTester { public static void main(String args[]) { int j, src =2, des=3, hm=2; int[] sa = {100,200,300,400,500}; int[] da = {40,50,60,70,80}; system.arraycopy(sa,crc,da,des,hm); for(j=0;j<da.length;j++) System.out.pinr(da[j]); } None of these d

11 What replaces<#1> so that the product of all the elements in array d is returned?
Public static double getProduct() { double d[] = {100,-25,16,27,-102}; double product = 1; <#1> return product; } For(double j:d) product*=d[j]: For(int j=0;j<d.length;j++) Product=product * j; Product*=d[j]; For(double j:d) product *= j; More than one of these E-d&c

12 Which of these answers is the resulting array after running the following code?
Int[][] zorro=new int[3][4]; For(int row=0;row<zorro.length;row++) { for(int col=0;col<zorr.length;row++) { zorro[row][col] = col +1; } 0000, 1111, 2222 0123, 0123, 0123 1234, 1234, 1234 1111, 2222, 3333 None of these c

13 What is printed by System.out.println(intArray.lentth);?
Int[][] intArray = {{11,2}, {20,30}, {7,9}, {0,1}}; 2 4 8 None of these b

14 What is printed by Sytem.out.println(int.Array[2].length);?
Int[][]intArray={{11,2},{20,30},{7,9},{7.9},{0,1}}; 2 4 8 None of these a

15 Is an int type passed by reference or by vlue to a method?
Value neither b

16 Is it possible to have an array whose rows have differing numbers of columns?
Yes No y

17 Show how to determine the number of columns in a two-dimensional array, double d[][];
D[0].length D[].length D.length(0) None of these a

18 Show how to determine the number of rows in the two-d integer array, int z[][]
Length.z Length.z() Z.length() Z.length None of these d

19 Is a double type passed by reference or by value to a method?
neither b

20 Is a String passed by reference or by value to a method?
neither Nothing in java is passed by reference, and since a string is immutable, that assignment creates a new string object that the copy of the reference now points to. The originalreference still points to the empty string. This would be the same for any object, i.e., setting it to a new value in a method.

21 Is BankAccount object passed by reference or by value to a method?
neither a

22 An int a[] array is passed as an argument to a method
An int a[] array is passed as an argument to a method. The signature of the method is: public String calc(int b[]) which of the following is true? A new b array is created B is just a reference back to the original a array Changes in b do not affect a The a array is passed by value to the calc method None of these b


Download ppt "Arrays review."

Similar presentations


Ads by Google