1. What are the valid ways to declare an integer array named a? (Check all that apply.)
# int [] a;
# int a [];
# array int a;
# int array a;
# int [] a;
# int a [];
1/21
Term | Definition |
---|---|
1. What are the valid ways to declare an integer array named a? (Check all that apply.) # int [] a; # int a []; # array int a; # int array a; | # int [] a; # int a []; |
2. What is the index of the first element of an array? # –1 # 0 # 1 | 0 |
3. An array has 30 elements; what is the index of its last element?a # 29 # 30 # 31 | 29 |
4. What is the default value of the elements in an array of ints after declaration and instantiation of the array? # 0 # null # undefined | # 0 |
5. How do you access the element of array a located at index 6? # a{6} # a( 6 ) # a[6] | a[6] |
6. Which of the following assertions is true? # An array cannot be sized dynamically. # An array can be sized dynamically, but cannot be resized without instantiating it again. # An array can be sized dynamically and can also be resized without instantiating it again | # An array can be sized dynamically, but cannot be resized without instantiating it again. |
How do you retrieve the number of elements in an array ? # a . length( ) # a . length # a . size( ) # a . size | a.length |
8. All the elements of an array must be of the same data type. # true # false | true |
9. Array aggregate assignment is possible in Java. # true # false | false |
10. Aggregate comparison of arrays is possible in Java. # true # false | false |
13. What is the output of this code sequence? double [ ] a = { 12.5, 48.3, 65.0 }; System.out.println( a[1] ); | 48.3 |
14. What is the output of this code sequence? int [ ] a = new int [6]; System.out.println( a[4] ); | 0 |
15. What is the output of this code sequence? double [ ] a = { 12.5, 48.3, 65.0 }; System.out.println( a.length ); | 3 |
What is the output of this code sequence? int [ ] a = { 12, 48, 65 }; for ( int i = 0; i < a.length; i++ ) System.out.println( a[i] ); | 12 48 65 |
17. What is the output of this code sequence? int [ ]a ={12, 48, 65}; for(inti = 0; i < a.length; i++) System.out.println("a["+ i +"] = "+ a[i]); | a[0] = 12 a[1] = 48 a[65] = 65 |
18. What is the output of this code sequence? int s = 0; int[]a ={12, 48, 65}; for(inti = 0; i < a.length; i++) s += a[i]; System.out.println("s = "+ s); | s = 125 |
19. What is the output of this code sequence? int [] a = new int[10]; for(int i = 0; i < a.length; i++) a[i]= i + 10; System.out.println(a[4]); | 14 |
20. What is the output of this code sequence? double []a ={12.3, 99.6, 48.2, 65.8}; double temp = a[0]; for(int i = 1; i < a.length; i++) { if(a[i]> temp) temp = a[i]; } System.out.println(temp); | 99.6 |
What is the output of this code sequence? int []a ={12, 48, 65, 23}; int temp = a[1]; a[1]= a[3]; a[3]= temp; for(inti = 0; i < a.length; i++) System.out.print(a[i]+" "); | 12 23 65 48 |
27. This code assigns the value 10 to all the elements of an array a. int [ ] a = new int[25]; for ( int i = 0; i < a.length; i++ ) { } | for ( int i = 0; i < a.length; i++ ) { array[i] = 10; } |
28,29,30,31, 36,37,38,39, 40,41,42,43, 44,45,46,47,48 |