0% found this document useful (0 votes)
14 views7 pages

Array & String

The document contains a series of multiple-choice questions related to Java programming concepts, including array indexing, string manipulation, wrapper classes, and search algorithms. Each question provides four options, from which the correct answer must be selected. The questions cover a range of topics such as method prototypes, character class methods, and sorting algorithms.

Uploaded by

rat ctrl
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)
14 views7 pages

Array & String

The document contains a series of multiple-choice questions related to Java programming concepts, including array indexing, string manipulation, wrapper classes, and search algorithms. Each question provides four options, from which the correct answer must be selected. The questions cover a range of topics such as method prototypes, character class methods, and sorting algorithms.

Uploaded by

rat ctrl
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

1.

Java statement to access the 5th element of an array is:


A. X[4]
B. X[5]
C. X[3]
D. X[0]

2. The output of "Remarkable".substring(6) is:


A. Mark
B. Emark
C. Marka
D. Able

3. Which of the following is the wrapper class for the data type char?
A. String
B. Char
C. Character
D. Float

4. The method compareTo() returns ............... when two strings are equal and in
lowercase :
A. True
B. 0
C. 1
D. False

5. Assertion (A): In Java, statements written in lower case letter or upper case
letter are treated as the same.
Reason (R): Java is a case sensitive language.
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 true and Reason (R) is false
D. Assertion (A) is false and Reason (R) is true

6. What will be the output for: [Link]([Link]('1'));


A. 0
B. 1
C. A
D. True
7. Write the output of the following String methods:
A. "ARTIFICIAL".indexOf('I')
B. "DOG and PUPPY".trim().length()

8. Read following question:


int P[ ] = {12, 14, 16, 18};
int Q[ ] = {20, 22, 24};

Place all elements of P array and Q array in the array R one after the other.
(a) What will be the size of array R[ ] ?
(b) Write index position of first and last element?
9. The Scanner class method used to accept words with space:
A. next()
B. nextLine()
C. Next()
D. nextString()

10. The keyword used to call package in the program:


A. extends
B. export
C. import
D. package

11. What value will [Link]([Link](15.3)) return?


A. 16.0
B. 16
C. 4.0
C. 5.0

12. Write a method prototype name check() which takes an integer argument and
returns a char:
A. char check()
B. void check (int x)
C. check (int x)
D. char check (int x)
13. The String class method to join two strings is:
A. concat(String)
B. <string>.joint(string)
C. concat(char)
D. Concat()

14. The output of the function "COMPOSITION".substring(3, 6):


A. POSI
B. POS
C. MPO
D. MPOS

15. Give the output of the following Character class methods:


(a) [Link] ('a')
(b) [Link]('#')

16. Give the output of the following Character class methods:


(a) [Link] ('a')
(b) [Link]('#')

17. Consider the given array and answer the questions given below:
int x[ ] = {4, 7, 9, 66, 72, 0, 16};
(a) What is the length of the array?
(b) What is the value in x[4]?

18. Return data type of isLetter(char) is ............... .


A. Boolean
B. boolean
C. bool
D. char
19. Method that converts a character to uppercase is ............... .
A. toUpper()
B. ToUpperCase()
C. toUppercase()
D. toUpperCase(char)

20. Give output of the following String methods:


"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')
A. 0
B. 5
C. 6
D. -5

21. Give the output of the following code:


[Link]("Good".concat("Day"));
A. GoodDay
B. Good Day
C. Goodday
D. goodDay

22. A single dimensional array contains N elements. What will be the last subscript?
A. N
B. N - 1
C. N - 2
D. N + 1

23. What will be the output of the following code?


[Link]("Lucknow".substring(0,4));
A. Lucknow
B. Luckn
C. Luck
D. luck

25. State the data type and value of res after the following is executed:
char ch = '9';
res= [Link](ch);

26. Write the output for the following:


String s1 = "phoenix"; String s2 ="island";
[Link]([Link](0).concat([Link](2)));
[Link]([Link]());

27. Give the output of the following statements:

String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};


[Link](x[3]);
[Link]([Link]);

28. Given array int x[] = {11, 22, 33, 44}; the value of x[1+2] is ........... .

A. 11
B. 22
C. 33
D. 44

29. If int arr[] = {3, 5, 7, 9}; what is the value of [Link]?


A. 3
B. 5
C. 4
D. Cannot be determined

30. Given array int z[] = {15, 16, 17}; It will occupy ........... bytes in memory.
A. 3
B. 12
C. 24
D. 64
31. A linear search ...........
A. can be used with sorted arrays only
B. can be used with unsorted arrays only

C. can be used with both sorted and unsorted arrays ✓


D. cannot be used with arrays

32. A binary search


A. can be used with sorted arrays only
B. can be used with unsorted arrays only
C. can be used with both sorted and unsorted arrays
D. cannot be used with arrays

33. Which of the following statements is true?


A. Binary search is less efficient than the sequential search.
B. Binary search is less efficient than the linear search.
C. Binary search is more efficient than the sequential search.
D. Binary search is as efficient as the sequential search.

34. In ........... search, the algorithm uses the middle value of the array for the search
operation.
A. Binary
B. Linear
C. Bubble
D. Selection

35. Total size of array A having 25 elements of char type is ............... .


A. 25 bytes
B. 50 bytes
C. 100 bytes
D. None of these
36. Which of the following statements are valid array declaration ?
A. int number( );
B. float average[ ];
C. double[ ] marks;
D. counter int[ ];

37. Consider the following code


int number[ ] = new int[5];
After execution of this statement, which of the following are True ?
A. number[0] is undefined
B. number[5] is undefined
C. number[2] is 0
D. [Link] is 5

38. Given that int z[ ][ ] = {{2, 6, 5}, {8, 3, 9}}; What will be value of z[1][0] and z[0][2] ?
A. 2 and 9
B. 8 and 5
C. 2 and 5
D. 6 and 3

39. Given array 12, 3, 8, 5. What will be array like after two passes of selection sort ?
A. 12, 3, 8, 5
B. 3, 5, 8, 12
C. 3, 8, 5, 12
D. 3, 5, 12, 8
40. Given an array 12, 3, 8, 5. What will be array like after two passes of bubble sort?
A. 12, 3, 8, 5
B. 3, 8, 12, 5
C. 3, 5, 8, 12
D. 12, 3, 5, 8

You might also like