Computer X Prelims 24-25
Computer X Prelims 24-25
iii. Searching algorithm can be applied for which of the following types?
a) int b) char c) String d) All of the above
iv. Which of the following keyword is used to stop the execution of any program segment?
a) continue b) stop c) break d)System.exit(0);
vii. Which of these method of class String is used to compare two String objects for their equality?
a) equals() b) Equals() c) isequal() d) Isequal()
ix. Which of these data type value is returned by equals() method of String class?
a) String b) int c) Boolean d) all of the mentioned
xv. Assertion (A): Integer class can be used in the program without calling a package.
Reason (R): It belongs to the default package java.lang.
(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
xviii. Assertion (A): An argument is a value that is passed to a method when it is called.
Reason (R): Variables which are declared in a method prototype to receive values are called actual
parameters.
(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
xx. Which will be the function returns when there is no occurrence of the char passed to indexOf() function?
a) 0 b) 1 c) -1 d) null
Question no 2. [10x2=20]
v) Rewrite the following program segment using while instead of for statement
int f = 1, i;
for (i = 1; i <= 5; i++) {
f *= i;
System.out.println(f);
}
vi) 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]?
vii) Sam executes the following program segment and the answer displayed is zero irrespective of any non zero
values are given. Name the error. How the program can be modified to get the correct answer?
void triangle(double b, double h)
{
double a; a = ½ * b * h;
System.out.println(“Area=”+a);
}
int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
System.out.print((char) b);
System.out.println( );
}ix) Write the output for the following:
int p = 9;
while (p<=15)
{
p++;
if(p== 10)
continue;
System.out.println(p);
}
Question no 4.
Write a program to input a number and check whether it is 'Disarium Number' or not. Display the
message accordingly.
DISARIUM: A number will be called DISARIUM if sum of its digits powered with their respective position is
equal to the original number.
(Workings 11 +32 +53= 135, some other DISARIUM are 89, 175, 518 etc)
Question no 5.
Write a Java program to input a sentence from the user in lowercase and capitalize the first and the last
characters of every word in it.
Sample Input: i love java for school.
Sample Output: I LovE JavA FoR SchooL
Question no 6.
Write a program to take twenty double value in a SDA.Now, Sort and display them in descending order using
the bubble sort technique.
Question no 7.
1. void display(String str, char ch) — checks whether the word str contains the letter ch at the
beginning as well as at the end or not. If present, print 'Special Word' otherwise print 'No special
word'.
2. void display(String str1, String str2) — checks and prints whether both the words are equal or not.
3. void display(String str, int n) — prints the character present at n th position in the word str.
Question no 8.
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:
int year[]={1982,1985,1987,1989,1992,1993,1994,1997,1999,2000};
******************************************************************************************