Assignment1 SDA Section A
Assignment1 SDA Section A
Assignment 1
1. The number of bytes occupied by an array of int[ ] type with 7 elements is:
Reason (R): The size of an array is equal to the number of elements in the list.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion
(A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
5. Differentiate between
(b) Declare an array of float type initialised to 4.6, 3.9 and 5.2
a. buses.length
b. buses.length( )
c. buses.length[ ]
d. buses.size( )
8. Which is not a true statement about an array?
9. Which of the following statements can be used to extract the third character
a. st[2].charAt(3);
b. st[3].charAt(2);
c. st[2].charAt(2);
d. st[1].charAt(2);
class First
{ int a[]={5,1,15,20,25};
int i,j;
int m;
i=++a[1];
j=a[2]++;
m=a[i++];
Place all the elements of array b and a in another array c one after the other and answer the
questions:
System.out.println(x[3].length());
15. Name the search algorithm which compares the sought key value with the key value of middle
element of the array at each stage.
16. Write a single line of code to print 4th character from a 3rd element of a string array Str[ ].
int a[ ] = {6,5,4,3,2,1};
int x;
for(x=5;x>0;)
System.out.println(a[--x]);
System.out.println(a[3].length());
a. Sequential b. Random
a. 40 bytes b. 14 bytes
c. 7 bytes d. 28 bytes
21. What will be the output of the following code:
a[0]=23;
a[3]= a[1];
System.out.println(“Sum=”+c);
a. 26 b. 23
c. 25 d. 27
22. For a given array int x[]= {11, 22, 33, 44, 55}; the value of a x[1+2] is
a. 11 b. 22
c. 33 d. 44
i. p = x.length
27. State the total size in bytes of the arrays a[ ] of char data type and p[ ] of float type which have 4
elements.
30. If int n[ ] = {1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
x = Math.pow(n[4], n[2);
y = Math.sqrt(n[5] + n[7]);
31. Find the errors in the given program segment and rewrite the statements assign values to an
integer array.
System.out.println(arr);
i) p = x.length;
42. A Single Dimensional array contains N elements. What will be the last subscript?
1. int m[ ] = {2,4,6,8}:
System.out.println(m[1] + ‘ ’+ m[2]);
2. int al ] = { 2, 4, 6, 8, 10} ;
a[0]=23;
a[3]=a[1]:
int c= a[0]+a[1];
System.out.println("Sum = "+c);
System.out.println(a[2+1]);
for(i=0;i<=1;i++)
{ s=a[i]+a[3-i];
System.out.println(s);
int a=1;
Page 4 of 8
a=a+i*ar1[i];
System.out.println(a);