You are on page 1of 5

COMPUTER APPLICATIONS – X

1st PRACTICE TEST (2022 – 23)


CHAPTERS – STRING & ARRAY
Time : 2 hrs Max Marks : 100

General Instructions
1. You will not be allowed to write during the first 15 minutes. This time is to be spent in reading the
question paper.
2. The time given at the head of this paper is the time allowed for writing the answers.
3. Attempt all questions from Section A and any 4 questions from section B.
4. The intended marks for questions or parts of questions are given in brackets [].
Section A [40 Marks]
(All questions are compulsory)
Question 1
Choose the correct answer and write the correct option.
(i) The return type of charAt() method is _____. [1]
a) String
b) int
c) float
d) None of the above
(ii) This is how a String can be created in Java:- [1]
a) String st = “test”;
b) String st = new String(new char[]{‘t’ , ‘e’ , ‘s’ , ‘t’});
c) Both a) and b)
d) None of the above
(iii) Which of the following statement is not correct :- [1]
a) The isUpperCase(char)-method is used to check whether a character is in uppercase or not and
it’s return type is boolean.
b) The toUpperCase(char)- method is used to convert a character from lowercase to uppercase and
it’s return type is String
c) The return type of st.toUpperCase() – method is boolean and the return type of
toUpperCase(char) – method is char.
d) Both b) and c)
(iv) Which of the following statement is true :- [1]
a) length is associated with String and length() is associated with Arrays.
b) length is used to determine the number of characters present in the string and length() is used
to determine the number of elements that the array can store.
c) length is associated with Arrays and is used to determine the number of elements that the array
can store and length() is associated with Strings and is used to determine the number of
characters present within a string without considering the spaces within the String.
d) None of the above.
(v) The size of an array is of type ____. [1]
a) long
b) short
c) int
d) float
(vi) If an array is created using the ‘new’ keyword and with a negative size , then the following thing will
happen :- [1]
a) We will get a blank output screen.
b) We will get Compile Time Error (i.e. Syntax Error) saying NegativeSizeNotAllowed
c) We will get Run Time Exception saying NegativeArraySizeException
d) None of the above
(vii) If we use to check the equality of two strings using == operator , we will get ___. [1]
a) Compile Time Error (i.e. Syntax Error)
b) Run Time Exception
c) We will get a blank output screen
d) None of the above
(viii) It can be used to check whether two Strings are equal or not:- [1]
a) equals() - method
b) compareTo()- method
c) both a) and b)
d) None of the above
(ix) While calling/invoking the indexOf() and substring()– methods , we have to pass __ and __type values
respectively. [1]
a) int and String
b) char and int
c) int and char
d) None of the above
(x) Arrays can be created only by using the ‘new’ keyword. [1]
a) true
b) false
(xi) It divides the array into parts and then performs the searching operation :- [1]
a) Linear Search
b) Binary Search
c) Bubble Sorting
d) Selection Sorting
(xii) In this process , the largest element is pushed to the last position and the process is continued till the task is done
a) Linear Search [1]
b) Binary Search
c) Bubble Sorting
d) Selection Sorting
(xiii) It is used to concat two strings :- [1]
a) + operator
b) concat() – method
c) both a) and b)
d) None of the above
(xiv) arr[12] is the ____ element within the array. [1]
th
a) 12 element
b) 13th element
c) Both a) and b)
d) None of the above
(xv) Which of the following statement is correct :- [1]
a) trim() – method is used to remove the extra spaces present at either sides of a string and in
between as well.
b) trim() – method is used to remove only the extra spaces present at the left side of a string.
c) trim() – method is used to remove only the extra spaces present at the right side of a string.
d) None of the above
(xvi) “friendship”.charAt(10) will give _____. [1]
a) p
b) Blank Output Screen
c) Compile Time Error
d) Run Time Exception
(xvii) The “disco”.lastIndexOf(‘D’) – method will give ____. [1]
a) Blank Output Screen
b) -1
c) 0
d) Run Time Exception
(xviii) The return type of endsWith() – method is ___. [1]
a) int
b) char
c) String
d) boolean
(xix) The functionality of the replace(char,char) method is :-
a) To replace the 1st character with the 2nd character at the first occurrence only.
b) To replace the 1st character with the 2nd character at all occurrances.
c) To replace the 1st character with the 2nd character at the first and last occurrence.
d) None of the above.
(xx) What will be the output of the following snippet :-
System.out.println(“Friendship”.lastIndexOf(‘I’));
a) 2
b) 8
c) -1
d) Run Time Error
Question 2
(i) Define Array. Create a long array with size 15. [2]
(ii) Write two differences between == and equals() [2]
(iii) Differentiate between toUpperCase() and toUpperCase(char) [2]
(iv) State the method that : [2]
a) converts a string to a primitive float data type.
b) determines , if the specified character is an upper case character.
(v) Give the output of the following :- [2]
a) String[] arr = {“apple” , “brush” , “camera” , “decoration” , “establishment”};
System.out.println(arr[4].charAt(arr[0].length()+3));
b) System.out.println(“APPLE”.ToLowerCase().compareTo(“APPLEAPPLE”));
(vi) Create a String “super” using the new Keyword and write a statement to display its length. [2]
(vii) What is the difference between these two statements: [2]
a) int sum[ ]=new int[10]
b) sum[1]=10;
(viii) What will be the output of the following program? [2]

(ix) What is Unicode? How can you get the unicode value of a Java character? [2]
(x) Give the output of the following program fragment:
String s="String";
int a=12,b=45;
System.out.println(s+a+b);
System.out.println(a+s+b);
System.out.println(a+b+s);
Section B [60 Marks]
(Attempt any four questions)

Question 3 [15]
Write a program to bubble-sort the following set of values in ascending order: 5,3,8,4,9,2,1,12,98,16
OUTPUT: 1 2 3 4 5 8 9 12 16 98
Question 4 [15]
Write a program to input 10 positive or negative numbers (no zero) into an integer array and shift all positive
numbers to the beginning of the array and negative numbers to the end of the array, without changing the
order of the numbers.For example, if the array contains the following elements:
Question 5 [15]
Write a program to store 6 elements in an array P and 4 elements in an array Q. Now , produce a third array R ,
containing all the elements of array P and Q. Display the resultant array.

Input Input Output


P[] Q[] R[]
4 19 4
6 23 6
1 7 1
2 8 2
3 3
10 10
19
23
7
8
Question 6 [15]
Write a program to accept the year of graduation from school as an integer value from the user. Using the
binary search technique on the sorted array of integers given below , output the message “Record exists” if the
value input is located in the array. If not , output the message “Record does not exist”.
Sample Input :

n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010

Question 7 [15]
Write a program to input 10 numbers into an integer array and shift all even numbers to the beginning of the
array and odd numbers to the end of the array, without changing the order of the numbers.
Question 8 [15]
A ‘Happy Word’ is defined as :
Take a word and calculate the word’s value based on position of the letters in English alphabet. On the basis of
word’s value , find the sum of the squares of its digits. Repeat the process with the resultant number until the
number equals 1 (one). If the number ends with 1 then the word is called a ‘Happy Word’. Write a program to
input a word and check whether it is a ‘Happy Word’ or not. The program displays a message accordingly.
Sample Input : VAT
Place value of V = 22 , A = 1 , T = 20
[Hint: A=1 , B=2 , ------ , Z=26]
Solution: 22120 → 22 + 22 + 12 + 22 + 02 = 13 → 12 + 32 = 10 → 12 + 02
Sample Output:- A Happy Word
***

You might also like