0% found this document useful (0 votes)
42 views6 pages

Assignment1 SDA Section A

Uploaded by

valorantopop69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views6 pages

Assignment1 SDA Section A

Uploaded by

valorantopop69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Grade 10

Assignment 1

Single Dimensional Array Theory Questions

1. The number of bytes occupied by an array of int[ ] type with 7 elements is:

(a)56 (b) 7 (c) 14 (d) 28

2. Assertion (A): When an array is initialized, its size is not specified.

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)

(c) Assertion (A) is false and Reason (R) is true

(d) Assertion (A) is true and Reason (R) is false

3. int a[ ] = {2,3,4,5,6}, then a[ ].length will result in:

(a) 6 (b) 5 (c) a[5] (d) Syntax error

4. char ch[ ] = {'A', 'B', 'C', 'D'};

System.out.println (ch[1] + ch[3]);

What will be the output of the above code snippet ?

5. Differentiate between

i) searching and sorting

ii) Selection sort and bubble sort

iii) Linear Search and Binary Serach

6. Give the proper array declaration statement for the following:

(a) Declare an integer array that can hold 15 values.

(b) Declare an array of float type initialised to 4.6, 3.9 and 5.2

7. How do you determine the number of elements in an array?

int buses[] = new int[5];

a. buses.length

b. buses.length( )

c. buses.length[ ]

d. buses.size( )
8. Which is not a true statement about an array?

a. An array expands automatically when it is full.

b. An array is allowed to contain duplicate values.

c. An array understands the concept of ordered elements.

d. An array uses a zero index to reference the first element.

9. Which of the following statements can be used to extract the third character

from the second element of the String array st[ ]?

a. st[2].charAt(3);

b. st[3].charAt(2);

c. st[2].charAt(2);

d. st[1].charAt(2);

10. What will be the output of the following program:

class First

{ public static void main(String args[])

{ int a[]={5,1,15,20,25};

int i,j;

int m;

i=++a[1];

j=a[2]++;

m=a[i++];

System.out.print(i+“ ”+j+“ ”+m);

11. What is the output of the following?

boolean b[ ] = {true, false};

System.out.println (b[1] * 2);

12. int a [ ]={ 1, 5, 6, 8, 5 }; int b[ ]={ 0, 3, 7, 3 };

Place all the elements of array b and a in another array c one after the other and answer the
questions:

(a) What will be the size of the resultant array ?

(b) Find the output: System.out.println(Math.pow(c[6], c[0]));


13. How many bytes of memory will the following array use?

double b[ ] = new double[6];

(a) 48 bytes (b) 24 bytes

(c) 48 bits (d) 24 bits

14. Give the output of the following statements:

String x[ ] = {"Apple", "Blueberry", "Grapefruit", "Tomato", "Watermelon"};

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.

(a) Bubble sort (b) Linear search

(c) Binary search (d) Selection sort

16. Which of the following statement contains an error?

(a) int a[]= int[10];

(b) float d[]={1,2,3};

(c) int a[]= {1,2}; int b[]; b=a;

(d) All the above

16. Write a single line of code to print 4th character from a 3rd element of a string array Str[ ].

17. What will be the output of the following code snippet?

int a[ ] = {6,5,4,3,2,1};

int x;

for(x=5;x>0;)

System.out.println(a[--x]);

18. String a[]= {“MI”, “SAMSUNG”, “MICROMAX”, “ONE PLUS”};

Give the output of the following statement:

System.out.println(a[3].length());

19. Array elements are always stored in __________ memory locations.

a. Sequential b. Random

c. Sequential and random d. Binary

20. The array int a[ ] of 7 elements occupies ….

a. 40 bytes b. 14 bytes

c. 7 bytes d. 28 bytes
21. What will be the output of the following code:

int a= {2, 4, 6, 8, 10};

a[0]=23;

a[3]= a[1];

int c = a[0] +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

23. If int x[] = { 4, 3, 7, 8, 9, 10}; What will be the values of p and q?

i. p = x.length

ii. q= x[2] + x[5] *x[1];

24. Give example and explain direct initialization of an array?

25. What is meant by the subscript of an array?

26. Write the difference between length and length( ) functions.

27. State the total size in bytes of the arrays a[ ] of char data type and p[ ] of float type which have 4
elements.

28. What is an array? Write a statement to declare an integer array of 10 elements

29. Declare an Array of characters while initializing it with vowels.

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.

int a = new int(5);

for(int i=0; i<= 5; i++) a[i] = i;

32. What will this code print?


int arr[]= new int [5];

System.out.println(arr);

(i) 0 (ii) 0000

(iii) Value stored in arr (iv) garbage value

33. If int x[ ]= {4, 3, 7, 8, 9, 10}; what are the values of p and q?

i) p = x.length;

ii) q= x[2] + x[5] *x[1];

34. Which of the following is the correct usage?

(a) int a[-40] (b) int a[40]

(c) float a[0-40] (d)None

35. Which element is represented by a[10]?

(a) 10th (b) 9th

(c) 11th (d) None

36. Cell numbers of a dimensional array are also known as:

(a) packets (b) blocks

(c) subscripts (d) compartments

37. A dimensional array is also known as:

(a) subscripted variable (b) actual variable

(c) compound variable (d) None

38. An array element can be accessed through:

(a) dots (b) element name

(c) index number (d) none

39. The following statement

int code[ ] = {25, 37, 38, 42};

(a) assigns 37 to code[1] (b) assigns 25 to code[1]

(c) assigns 38 to code[3] (d) assigns 42 to code[0]

40. The elements of array[50] are numbered..

(a) from 1 to 50 (b) from 0 to 49

(c) from 1 to 5 (d) None

41. Which of the following function finds the size of array?

char m[ ] = {'R', ‘A’, ‘T’,’E’,'N', ‘D’, ‘R’, ‘A’};


(a) m.sizeof( ) (b) m.elements of (m)

(c) m.length (d) None

42. A Single Dimensional array contains N elements. What will be the last subscript?

(a) N-1 (b) N

(c) N+1 (d) None

43. Give the output of the following:

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);

3. int al ]=new int [5]:

a[0]=4; a[1]=8; a[2]=7; a[3]=12; a[4]=3;

System.out.println(a[2+1]);

4. int a[4]= {2,4,6,8};

for(i=0;i<=1;i++)

{ s=a[i]+a[3-i];

System.out.println(s);

5. Predict the output:

int ar1[ ] = {1,2,3,4,5};

int a=1;

for (int i=0; i<5; i++)

Page 4 of 8

a=a+i*ar1[i];

System.out.println(a);

You might also like