CS 180 Assignment 6 Arrays
Which is a legal array declaration or definition? int[] []x[]; int *x; int x[5]; int[] x = {1,2,3};
D. String[names.length-1 ] = "Hello" ; 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" ;
for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(j = i) 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 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
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
A. for ( int j = 0; j < names.length; j++ ) 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++ ) C. for ( int j = names.length-1; j >= 0; j-- ) D. for ( int j = names.length; j >= 0; j++ )