1 / 6

CS 180

Assignment 6 Arrays. CS 180 . Which is a legal array declaration or definition? int[] []x[]; int *x; int x[5]; int[] x = {1,2,3};. Which of the following statements puts a reference to the String "Hello" in the last slot of the array?. String[] names = new String[10] ;

quiana
Télécharger la présentation

CS 180

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 6 Arrays CS 180

  2. Which is a legal array declaration or definition? • int[] []x[]; • int *x; • int x[5]; • int[] x = {1,2,3};

  3. Which of the following statements puts a reference to the String "Hello" in the last slot of the array? String[] names = new String[10] ; A. names[0] = "Hello" ; B. names[10] = "Hello" ; C. names[9] = "Hello" ; D. String[names.length-1 ] = "Hello" ;

  4. What will be the content of array variable table after executing the following code? • for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(j = i) • table[i][j] = 1; • else • table[i][j] = 0; A. 0 0 0 0 0 0 0 0 0 B. 1 0 0 0 1 0 0 0 1 C. This code will result in compiler error D. This code will result in Run Time Exception

  5. What will happen if you try to compile and run the following code? • public class Q { • public static void main(String argv[]){ • int anar[]=new int[5]; • System.out.println(anar[0]); • } • } A. Error: anar is referenced before it is initialized B. null C. 0 D. 5 E. 1

  6. Which of the following fragments prints out the slots of the array from last to first, skipping slots that contain null? A. for ( int j = 0; j < names.length; j++ ) if ( names[j] != null ) System.out.println( names[j] ); B. for ( int j = names.length; j < names.length; j++ ) if ( names[j] != null ) System.out.println( names[j] ); C. for ( int j = names.length-1; j >= 0; j-- ) if ( names[j] != null ) System.out.println( names[j] ); D. for ( int j = names.length; j >= 0; j++ ) if ( names[j] != null ) System.out.println( names[j] );

More Related