Revision Test (Key Answer)
Revision Test (Key Answer)
General Instructions:-
Question 1:
Choose the correct answer:
1. Assertion (A): Strings can be added using the operator ‘+’.
Reason (R ) : In java addition of constants of all data types is carried out in the same
way using ‘+ operator to obtain similar results.
a. Assertion (A) and Reason (R ) are true and Reason (R ) is the correct explanation
b. Assertion (A) and Reason (R ) are false
c. Assertion (A) is true and Reason (R ) is false
d. Assertion (A) false and Reason (R ) is true
2. Strings are
a. Mutable
b. Immutable
c. Primitive data types
d. None of the above.
a. Strings
b. Double dimensional arrays
c. Encapsulation
d. Message passing
Page 1 of 5
4. What will the code print?
int arr[] = new int [5];
System.out.println(arr);
a. 0
b. value stored in arr[0]
c. 0000
d. garbage value
9. Which one of the given statements is true for the following statement?
string1.compareTo(string2)
a. if string1 > string2 the result will be a negative integer i.e. < 0.
b. if string1 > string2 the result will be a positive integer i.e. > 0.
c. if string1 > string2 the result will be 0.
d. None of the above
Question 2:
1. Write any two differences between Bubble sort and Selection sort. [2]
int m[ ] = {4,6,8,12,16,3,9,7};
m[i]=m[i]+3;
3. What will be the value of s ? [2]
int m = 987654321;
String s = “ “;
while (m != 0) {
14
-7
Page 3 of 5
Section-B
Attempt all questions from this Section.
Each program should be written in such a way that it clearly depicts the logic of the
program.
Question 3:
Write a program to input a string and print each word of the string in the reverse order.
Sample Input:
Enter a string: My name is Raman
Sample Output
yM eman si namaR
import java.util.Scanner;
if (i != input.length()) {
result += " ";
}
start = i + 1;
}
}
Page 4 of 5
Annual Exam-Gr3-ICSE-SST-MAR 20
Question 4:
Define a class to accept four characters in two different one dimensional arrays x and y.
Check and print the message “identical” if the characters at the corresponding index positions
of x and y are same.
Example: Input: x[]={'x', 'y', 'z', 'w'} and y[]={'x', 'y', 'z', 'w'} Output: identical
import java.util.Scanner;
if (identical) {
System.out.println("identical");
} else {
System.out.println("not identical");
}
}
}
*****
Page 5 of 5