Arrays Review and Code Challenges

Slide Note
Embed
Share

Explore arrays in programming through a review of array values and initialization methods. Dive into code challenges involving array operations and manipulation to test your understanding. See the output of code snippets to further solidify your knowledge.


Uploaded on Oct 05, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. ARRAYS REVIEW

  2. WHAT IS THE VALUE OF GEM[1]? INT[] GEM ; { -102, 14, 5, 100, -100}; -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) 3 2 0 7 NONE OF THESE IF (CB[K]<3) ++COUNTER; RETURN COUNTER; }

  4. WHICH OF THE FOLLOWING LINES OF CODE IS A PROPER WAY TO DECLARE AND INITIALIZE THE C ARRAY? INT[] C = MEW OMT[] {1. 2. 3. 4}; INT[10] C = {1. 2. 3. 4}; INT C = {1, 2, 3, 4}; INT[] C + NEW INT {1, 2, 3, 4}; BOTH A AND B

  5. 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) J < A.LENGTH 1 { J < A.LENGTH() FOR(INT J=0;<*1>;++J) J <= A.LENGTH ++A[J]; J < A.LENGTH + 1 } NONE OF THESE

  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) 3 { 19 FOR(INT J=0;<*1>;++J) 18 ++A[J]; 20 } NONE OF THESE

  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++) { ANCP SWITCH(VV[J]) MBOD { AOCQ CASE 0: ABCD SYSTEM.OUT.PRINT(X[J]); NONE OF THESE BREAK; CASE 1: SYSTEM.OUT..PRINT(Y[J+1]); } } } }

  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; 14 15 16 THROWS AN EXCEPTION NONE OF THESE INT SUM = 0; FOR(INT J=0;J<3;J++) { SUM+=(A[J+1]*B[J]*B[J+1]); } SYSTEM.OUT.PRINTLN(SUM); } }

  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}; 102 44 56 THROWS AND EXCEPTION NONE OF THESE 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); } }

  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]); } } 1002003007080 1002007080500 405030040080 405060300400 NONE OF THESE

  11. WHAT REPLACES<#1> SO THAT THE PRODUCT OF ALL THE ELEMENTS IN ARRAY D IS RETURNED? FOR(DOUBLE J:D) PRODUCT*=D[J]: PUBLIC STATIC DOUBLE GETPRODUCT() { FOR(INT J=0;J<D.LENGTH;J++) DOUBLE D[] = {100,-25,16,27,-102}; PRODUCT=PRODUCT * J; DOUBLE PRODUCT = 1; FOR(INT J=0;J<D.LENGTH;J++) <#1> PRODUCT*=D[J]; RETURN PRODUCT; FOR(DOUBLE J:D) PRODUCT *= J; } MORE THAN ONE OF THESE

  12. WHICH OF THESE ANSWERS IS THE RESULTING ARRAY AFTER RUNNING THE FOLLOWING CODE? INT[][] ZORRO=NEW INT[3][4]; 0000, 1111, 2222 FOR(INT ROW=0;ROW<ZORRO.LENGTH;ROW++) { 0123, 0123, 0123 FOR(INT COL=0;COL<ZORR.LENGTH;ROW++) { 1234, 1234, 1234 ZORRO[ROW][COL] = COL +1; 1111, 2222, 3333 } NONE OF THESE }

  13. WHAT IS PRINTED BY SYSTEM.OUT.PRINTLN(INTARRAY.LENTTH);? 2 4 INT[][] INTARRAY = {{11,2}, {20,30}, {7,9}, {0,1}}; 8 0 NONE OF THESE

  14. WHAT IS PRINTED BY SYTEM.OUT.PRINTLN(INT.ARRAY[2].LENGTH);? 2 4 INT[][]INTARRAY={{11,2},{20,30},{7,9},{7.9},{0,1}}; 8 0 NONE OF THESE

  15. IS AN INT TYPE PASSED BY REFERENCE OR BY VLUE TO A METHOD? REFERENCE VALUE NEITHER

  16. IS IT POSSIBLE TO HAVE AN ARRAY WHOSE ROWS HAVE DIFFERING NUMBERS OF COLUMNS? YES NO

  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

  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

  19. IS A DOUBLE TYPE PASSED BY REFERENCE OR BY VALUE TO A METHOD? REFERENCE VALUE NEITHER

  20. IS A STRING PASSED BY REFERENCE OR BY VALUE TO A METHOD? REFERENCE VALUE NEITHER

  21. IS BANKACCOUNT OBJECT PASSED BY REFERENCE OR BY VALUE TO A METHOD? REFERENCE VALUE NEITHER

  22. 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

More Related Content