CL 10 - COMP APP - QUESTION PAPER-Answer key
CL 10 - COMP APP - QUESTION PAPER-Answer key
Answers to this Paper must be written on the paper provided by the school.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers. This
Paper is divided into two Sections.
Attempt all questions from Section Aand any 4 questions from Section B.
The intended marks for questions or parts of questions are given in brackets.
SECTION A (10 Marks)
Attempt all questions
Question 1. [20]
(iii) Which of the following declaration and initialization is the below line equivalent to?
String str = new String( ) ;
(a) String str = “”;
(b) String str = “0”;
(c) String str = null;
(d) String str = “\0”;
(iv) The element is x[4] of the array {3, 5, 7, 12, 16, 18, 20, 35, 42, 89} is:
(a) 16 (b) 12 (c) 7 (d) 18
(v) You can execute ----------------- methods even when no objects of a class exist,
whereas -------------- methods can be executed only in relation to a particular object,
so if no objects exist, you have no way to execute any of the instance methods
defined in the class.
(a) class , instance (b) Instance , class
Page 1 of 4
{
case 1:System.out.println(“Case 1”);
break;
if int x=5
x += x++ + ++ x + --x + x;
x) Java uses the 16 bits ______ character set to represent the character data.
Math.abs(Math.floor(-5.9));
Page 2 of 4
(xiv) Rather than the use of Character.isLowerCase(ch), what other test can you use to
check whether the character is lowercase or not?0
(a) if( ch >=’a’ && ch<=`z’ ) (b) if( ch >=’A’ && ch<=`Z’ )
(xv) (xv) For every object, separate memory is allocated to its __________ variables.
(xvi) What is the difference between the compareTo() and equals() method?
(a) Return type of compareTo() returns an integer and equals() returns boolean
(b) Knowledge of the string compareTo() method returns the lexicographic status
while equals() returns only whether the strings are equal or not
(c) Both (a) and (b)
(d) They are the same functions, with name changed
(xvii) The statement to invoke the default constructor of a class “State” is _________
(c) State obj= new State() ; (d) State obj= new State(int a)
char c=’B’;
int i=4;
System.out.print(c+i);
System.out.print((int)c+i);
(xix) Which keyword causes an immediate exit from the switch case or loop?
(xx) Within a string x, and the character ch, what is the way to call the indexOf() method?
Question 2. [20]
Page 3 of 4
Ans. String s = “ Dev Kumar”;
int i = 0;
while(s.charAt(i) != ` `)
i++;
(ii) What is the difference between static and non-static methods in a class?
Static methods have the static keyword
No object is required to invoke a static method
Non-static methods have no static keyword
An object is necessary to invoke the non-static methods
(iii) What is the output of the following code:
"abracad".endsWith("abc")&& "optim".startsWith("opi")
Ans. False
Ans: a=16.0
(vi) Find the errors in the given program segment and re-write the statements correctly
to assign values to an integer array.
int a = new int (5);
for(int i =0; i <=5; i + +)
a[i] = i;
Ans: int a[]=new int[5];
for(int i=0;i<5;i++)
a[i]=i;
(vii) What will be the output of the following:
int val, sum, n=550;
when
i) val=500
ii) val=1600
sum=n+val>1750?400:200;
System.out.println(sum);
Ans:i)200
Page 4 of 4
ii)400
(viii) How many times the loop will be executed.
for(int x=1;x<=10;x++)
{
System.out.println(x);
if(x==5)
break;
}
Ans: 5 times
(ix) What are Relational operators? Explain the different types of Relational operators?
Relational operators are used to compare the relationship between two data-items
in a conditional expression. For eg. >, <, >=, <=, ==, !=
(x) What will be the output of the following
class First{
public static void main(String args[])
{
int a[]={5,1,15,20,25};
int i,j;
int m;
i=++a[1];
j=a[2]++;
m=a[i++];
System.out.print(i+” ”+j+” “+m);
}
}
Ans: 3 15 16
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.
int i,j,temp=0;
int a[]={5,3,8,4,9,2,1,12,98,16};
Page 5 of 4
for(i=0; i<=9; i++)
if(a[j]>a[j+1])
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} }}
System.out.print(a[i]+" ");
Question 4 : [15]
The following program is based on the specifications given below. Write a program in java
such that:
member methods:
void print() – to print the details i.e. name of the customer, no of calls and the bill amount
void calculate() – to calculate the telephone bill as per the following criteria based on the
number of calls
void main() – to create an object of the class and invoke the functions of the class
Page 6 of 4
/*Program to calculate the telephone bill of the customer */
import java.util.*;
int noc;
double bill;
String n;
System.out.println("Enter the name of the customer and the number of calls made by the
customer");
n=sc.nextLine();
noc=sc.nextInt();
if(noc<=100)
bill=0.0;
else
bill=2.5*(noc-100);
System.out.println("Name"+n);
System.out.println("No of calls"+noc);
System.out.println("bill "+bill);
Page 7 of 4
obj.input();
obj.calculate();
obj.print();
import java.util.*;
int noc;
double bill;
String n;
System.out.println("Enter the name of the customer and the number of calls made by the
customer");
n=sc.nextLine();
noc=sc.nextInt();
if(noc<=100)
bill=0.0;
else
bill=2.5*(noc-100);
Page 8 of 4
System.out.println("Name"+n);
System.out.println("No of calls"+noc);
System.out.println("bill "+bill);
obj.input();
obj.calculate();
obj.print();
Question 5 : [15]
Define a class to accept the names of 10 students in an array and print the words which begin
with “AM” and count the number of words beginning with “AM”.
n[i]=sc.next();
}
for(int i=0; i<=9; i++)
{
n[i]=n[i].toUpperCase();
if (n[i].startsWith("AM"))
c++;
}
System.out.println(c);
}
}//class ends
Question 6 : [15]
Write a program in Java to enter a sentence. Display the words which are only
palindrome.
Sample input: MOM AND DAD ARE NOT AT HOME
Page 9 of 4
Sample output: MOM
DAD
rev=m.charAt(j)+rev;
return rev;
}
public static void main()
{
int c=0,i=0,j;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = sc.nextLine();
str=str+" ";
String word="",revWord="";
while(i<str.length())
{
int p = str.indexOf(' ',i);
word=str.substring(i,p);
if(word.length()!=0)
{
revWord=reverse(word);
if(word.equalsIgnoreCase(revWord))
c++;
}
i=p+1;
}
System.out.println(c);
}
Question 8 : [15]
Page 10 of 4
i) double series(double n) with one double argument and returns the sum of the
series. Sum=1/1 +1/2 +1/3 +…..1/n
ii) double series(double a, double n) with two double arguments and returns the sum
of the series.
sum = 1/a2+4/ a5+7/ a8+10/ a11….. to n terms
*********************
Page 11 of 4