Sample QP-Comp-X
Sample QP-Comp-X
(i) Name the feature of java which is depicted in the above picture.
(a) Inheritance (b) Encapsulation
(c) Polymorphism (d) Data Abstraction
(ii) Which of the following types can be used for a non-returnable method?
(a) int (b) double
(b) float (d) void
(iii) Give the output of the following statement:
“SUCCESS”.indexOf(‘S’)+”SUCCESS”.lastIndexOf(‘S’)
(a) 0 (b) 5
(c) -5 (d) 6
(iv) State the type of the loop in the given program segment :
for (int i=5;i!=0;i-=2)
System.out.println(i);
(a) finite (b) infinite
(c) null (d) fixed
Question 2
(i) Consider the following two-dimensional array and answer the questions given below. [2]
int x[ ][ ] = {{4,3,2},{7,8,2},{8,3,10},{1,2,9}};
(a) What is the order of the array?
(b) What is the value of x[0][0] + x[2][2]?
(ii) Evalute the expression when x = 4: [2]
x += x++ * ++x %2.
(iii) Predict the output: [2]
(a) Math.pow(25,0.5)+Math.ceil(4.2);
(b) Math.round(14.7)+Math.floor(7.9);
(iv) String s1=”45.50”; String s2=”54.50”; [2]
double d1= Double.parseDouble(s1);
double d2= Double. parseDouble(s2);
int x= (int) (d1+d2);
What is the value of x?
(v) Kamal wants to display only the alphabets stored in a character array.While compiling [2]
the code,an error was displayed. Check for the statement with the error and write the
correct statement.
char arr[ ]={‘4’,’&’,’a’,’w’,’d’};
int i;
for(i=0;i<arr.length;i++)
{
if(Character.isLetter(arr))
System.out.println(arr);
}
(vi) How many times will the following loop execute? Write the output of the code:
int x=10;
while(true){
System.out.println(x++ *2);
if(x%3==0)
void print( int n) : To print whether the given number is a special number or not. A number is
said to be special number , if the sum of factorial of its digits is same as the
original number.
Example: 145 is a special number because 1!+4!+5! = 145
𝑥 𝑥2 𝑥3 𝑥4
double print( int x, int n): To print the sum of the series 1 + 1! + + + …𝑛
2! 3! 4!
Question 4 [15]
Write a program to input a string and convert into uppercase. Print the pair of vowels and the
number of pair of vowels occurring in the string.
Sample input: BEAST AND BEAUTIFUL
Sample output: Pair of vowels: EA,EA,AU
No:of pair of vowels:3
Question 5 [15]
Write a program to input the weights of ten people. Sort and display them in ascending order
using the selection sort technique.
Question 7 [15]
Define a class to overload the following methods:
(a) void display( )
EEEEE
DDDD
CCC
BB
A
(b) void display(int n) - To check whether the number is a lead number or not.A lead number
is the one whose sum of even digits is equal to the sum of odd digits.
Sample input: 3669
Sample output: sum of odd digits =3+9=12
Sum of even digits= 6+6=12
Hence,3669 is a lead number.
Question 8 [15]
Write a program to accept integer values into a 4 x 4 array . Display the array elements and find
the sum of left diagonal and right diagonal elements.
Sample input :
12 8 29 11
7 19 23 41
16 15 9 10
2 16 5 14
Sample output:
The array elements are:
12 8 29 11
7 19 23 41
16 15 9 10
2 16 5 14
Sum of left diagonal elements : 54
Sum of right diagonal elements: 51