8
8
8
n
Time allowed: Two hours
Answers to this Paper must be written on the paper provided separately.
ha
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.
as
This Paper is divided into two Sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].
ak
SECTION A
Pr
(Attempt all questions from this Section)
Question 1 [20]
Choose the correct answers and write the correct option.
(i) From the given array Y [][] = {{3, 4, 5},{6, 7, 8},{1, 2, 3}};
rs
The element at Y[2][2] is:
(a) 1 (b) 2 (c) 3 (d) 4
he
(ii) Decide how many searches using linear search it will require to successfully search for 2 from the below array?
15 12 2 3 4 5
(a) 2 (b) 3 (c) 4 (d) 5
ot
As in:
myObject.methodNoArgs();
oy
n
System.out.println (“Error reading from user”);
}
ha
(a) try block (b) Another catch block
(c) Either (a) or (b) (d) Any code
(x) The garbage collector feature in Java is used to avoid :
as
(a) Memory leak (b) Memory management
(c) Memory arrangement (d) Memory scope
(xi) In the class statement, “public static void main (String args[])” the keyword public stands for ______________.
ak
(a) The method is unchanging and implicitly final
(b) The method does not return a value
(c) The method is accessible to other classes.
Pr
(d) None of these
(xii) The statement to invoke the default constructor of a class “State” is __________________.
(a) State obj= new state ; (b) State obj = State();
rs
(c) State obj= new State(); (d) State obj= new State()
(xiii) Keywords are always in:
(a) Uppercase (b) Sentence case (c) Lowercase (d) Toggle case
he
switch(var)
{
Br
case 1:
System.out.println(“good”);
break;
case 2:
System.out.println(“better”);
al
break;
case 3:
oy
System.out.println(“best”);
break;
default:
System.out.println(“invalid”);
G
break;
}
}
If value 4 is passed to the function the output will be:
(a) best (b) invalid (c) good (d) better
2 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10
(xv) What is the other name of encapsulation?
(a) Information hiding (b) Information processing
(c) Information storing (d) Information reusing
(xvi) Method calls to objects use:
(a) Arrow notation (b) Caret notation (c) Dot notation (d) None of these
(xvii) What is the name given for:
“Sometimes there are two or more possible matches for an invocation of a method due to similar method
n
signature, so the compiler cannot determine the most specific match.”
(a) Multiple inheritance (b) Deep inheritance
ha
(c) Multiple invocation (d) Ambiguous invocation
(xviii) Assertion(A): All the math class methods are pure methods.
Reason (R): The math class methods depend solely on the input and have no side effects.
as
(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
ak
(d) Assertion (A) is false and Reason (R) is true
(xix) Read the following text, and choose the correct answer:
Polymorphism is the phenomenon of function overloading. You can have the same function names doing
Pr
completely different operations, as long as they differ in their argument lists. This especially helps because it
may be necessary to have the same name for widely differing functions as well.
Which of the following exhibits polymorphism?
(a) Inheritance (b) Data hiding
rs
(c) Function overloading (d) Abstraction
(xx) Assertion(A): The function Integer.parseInt() converts a String object to int.
Reason (R): The function Integer.toString() also converts a String object to integer.
he
(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
ot
ANSWERS
(i) (c) (ii) (b) (iii) (b) (iv) (c) (v) (b) (vi) (d) (vii) (a) (viii) (c) (ix) (c) (x) (a)
(xi) (c) (xii) (c) (xiii) (c) (xiv) (b) (xv) (a) (xvi) (c) (xvii) (d) (xviii) (a) (xix) (c) (xx) (c)
al
Question 2
(i) Evaluate the below Java line: [2]
oy
System.out.println(character.isUpperCase(‘Z’));
Ans. true is printed. As isUpperCase () returns true when the input to the function is an uppercase letter.
(ii) Fill in the blanks for the below code to change the array into an array that contains double the parent array. [2]
G
Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10 3
}
Print((2)_______);
Ans. (1)y[i] = 2 * x[i];
(2)y, or y,7
(iii) The below code snippet checks whether or not any character other than letter or digit is contained in the string
str. Fill in the blanks of the code in order to get the code correct. [2]
boolean (1)__________
n
for(int i = 0; i< str.length;i++)
ha
{
if(character.isLetterOrDigit(str.charAt(i)) == false)
{
System.out.println((2)__________)
as
(3)____________
break;
}
ak
}
if (flag == false)
{
}
Ans. (1)flag = false; Pr
System.out.println(“String is alphanumeric”);
rs
(2)”String is not purely alphanumeric”
(3)flag = true;
(iv) How would you take the input of a single character from the keyboard in a Java program? [2]
he
The above program assumes that user input necessarily ends with a ‘\n’ or newline character.
(v) Give any one advantage of using reference type of variables. [2]
Br
Ans. One clear advantage is that you can modify the contents of a class type of variable from inside a function.
This is a very big advantage.
(vi) How does the compareToIgnoreCase(String) method work? [2]
Ans. It compares the parent string and the argument characterwise. If the strings are identical(ignoring case), the
al
method returns zero. If the strings are different, then at the first index of difference, the difference in ASCII
values of the parent string and argument is returned by the method.
oy
The first function call returns true, and the second returns false, (although the strings match with ignore case,
but not identically). So, true && false returns false.
(viii) Suppose that you construct a function matches() so that it returns true whenever the two strings have some
matching prefix and suffix (of length at least 2) respectively. For the below call of the function, what should
this (assumed) correctly written function return? [2]
4 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10
“abcdef”.matches(“retef”);
Ans. As there is no prefix of “abcdef” that matches with suffix of “retef”, the value returned should be false.
(ix) Which operator in Java can do the same work as concat(String) of the String class? [2]
Ans. The + operator. For example:
“abc” + “def” is ”abcdef”
As also, “abc”.concat(“def”).
n
(x) Can a class have more than one constructor specified for itself? [2]
Ans. Yes, it can be done.
ha
SECTION B
as
(Answer any four questions from this Section)
The answers in the section should consist of the programs in either BlueJ environment or any
program environment with java as the base.
ak
Each program should be written using variable description/memonic codes so that logic of the
program is clearly depicted.
Flowcharts and algorithms are not required.
Question 3
Define a class to find the sum of first 75 natural numbers.
Ans. /**
Pr [15]
rs
* Write a description of class firstNnumbers here.
*
* @author (your name)
he
/**
* Constructor for objects of class firstNnumbers
*/
public firstNnumbers()
al
{
// initialise instance variables
}
oy
/**
* An example of a method - replace this comment with your own
G
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void generate(int y)
{
Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10 5
int sum = 0;
// put your code here
for(int i = 1;i <= y;i ++)
{
sum += i;
}
System.out.println(“Sum of first “+y+ “ integers =”+sum);
}
n
public static void main(String[] args)
ha
{
firstNnumbers fnn = new firstNnumbers();
fnn.generate(75);
}
as
}
Question 4 [15]
ak
Define a class to accept a number and check whether it is both divisible by 11 and contains at least a substring
which is also divisible by 11. For example:
99 is divisible by 11 but does not contain a number divisible by 11.
1331 is divisible by 11 and contains 33 that is also divisible by 11.
Pr
121 is divisible by 11 but does not contain a substring divisible by 11.
Ans. import java.io.*;
/**
* Write a description of class DivSubstrBy11 here.
rs
*
* @author (your name)
* @version (a version number or a date)
he
*/
public class DivSubstrBy11
{
// instance variables - replace the example below with your own
ot
private int x;
Br
/**
* Constructor for objects of class DivSubstrBy11
*/
public DivSubstrBy11()
{
al
try {
// initialise instance variables
oy
catch(IOException ie)
{}
catch(NumberFormatException nfe)
{}
}
6 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public boolean divBy11()
{
n
// put your code here
return (x%11 == 0);
ha
}
public boolean assess(int a, int b)
{
String str = String.valueOf(x);
as
int sum = 0;
for(int i = a; i <= b; i ++)
{
ak
sum =sum*10 + (str.charAt(i)-’0’);
}
if (sum % 11 == 0)
{
Pr
return true;
}
else {
return false;
rs
}
}
public boolean subAssess()
he
{
String str = String.valueOf(x);
boolean flag = true;
for(int i = 0;i < str.length(); i ++)
ot
{
for (int j = i + 1; j < str.length(); j ++)
{
Br
if (i == 0 && j == str.length() - 1)
{
continue;
}
al
else {
if(assess(i,j) == true)
{
oy
flag = false;
break;
}
G
}
}
if (flag == false)
{
break;
}
Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10 7
}
return (flag != true);
}
public static void main(String[] args)
{
DivSubstrBy11 dsb = new DivSubstrBy11();
if(dsb.divBy11() == true && dsb.subAssess() == true)
{
n
System.out.println(“YES, it is.”);
}
ha
else {
System.out.println(“NO, it is not.”);
}
}
as
}
Question 5 [15]
ak
Define a class that accepts a number and outputs the value of n, such that:
a. When the number is even, find n such that 2n.x is the number
b. When the number is odd, find n such that 2n.x + 1 is the number.
Pr
Ans. import java.io.*;
/**
* Write a description of class ExpOf2EvOd here.
*
rs
* @author (your name)
* @version (a version number or a date)
*/
he
private int n;
/**
Br
x = 0;
n = 0;
try {
oy
}
catch(IOException ie)
{}
catch(NumberFormatException nfe)
{}
}
8 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void findExpEvOd()
n
{
// put your code here
ha
if (x % 2 == 0)
{
int y = x;
while (y%2 ==0 )
as
{
y/=2;
n++;
}
ak
System.out.println(“Value of even exponent =”+ n);
}
else {
int y = x - 1;
Pr
while (y%2 == 0)
{
y/=2;
n++;
rs
}
System.out.println(“Value of odd exponent =”+n);
}
he
}
public static void main(String[] args)
{
ExpOf2EvOd eeo = new ExpOf2EvOd();
ot
eeo.findExpEvOd();
}
}
Br
Question 6 [15]
Write a program to find out whether a string has the same three characters at the beginning as at its end.
Report whatever the case may be. For example:
al
say123say
This is such a string
oy
daydavis323yaad
This is not such a string
whyisitwho
G
Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10 9
/**
* Write a description of class CompStrings here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CompStrings
{
// instance variables - replace the example below with your own
n
private int x;
ha
public static void main(String[] args)
{
String str;
Scanner sc = new Scanner(System.in);
as
str = sc.next();
str = str;
if(str.length() < 3)
{
ak
System.out.println(“This is too short. “);
}
else {
if(str.endsWith(str.substring(0,3)) == true)
Pr
{
System.out.println(“This is such a string. “);
}
else {
rs
System.out.println(“This is NOT such a string. “);
}
}
he
}
}
Question 7 [15]
ot
Write a Java program that takes as input a string containing both alphabets and numbers. It should output the
strings with only alphabets (in order) and only digits (in order). For example:
Dev23er45 (as input)
Br
Output:
Dever
2345
al
*
* @author (your name)
* @version (a version number or a date)
G
*/
public class SepLettDigi
{
// instance variables - replace the example below with your own
private int x;
public static void main(String[] args)
10 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10
{
String letters = “”, digits = “”;
Scanner sc = new Scanner(System.in);
String str = sc.next();
for(int i = 0;i < str.length(); i ++)
{
if(Character.isLetter(str.charAt(i)))
{
n
letters += (str.charAt(i));
}
ha
else {
if(Character.isDigit(str.charAt(i)))
{
digits+= (str.charAt(i));
as
}
}
}
System.out.println(“The letters are “+letters);
ak
System.out.println(“The digits are “+digits);
}
}
Question 8
Pr [15]
Design a class that takes as input an integer n from the user. Take n inputs from the user. Print out the digit
that occurs most frequently in the entire set of numbers entered. For example: for 7 numbers,
rs
12 21 34 46 62 29 98
2 occurs most frequently.
Ans. import java.io.*;
he
/**
* Write a description of class RepeatDigits here.
*
* @author (your name)
ot
{
// instance variables - replace the example below with your own
private int []x;
int n;
al
/**
* Constructor for objects of class RepeatDigits
oy
*/
public RepeatDigits()
{
// initialise instance variables
G
x = new int[10];
for(int i =0;i<10;i++)
{
x[i]=0;
}
}
Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10 11
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void readNos()
{
n
// put your code here
try{
ha
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine()), a, y;
for (int i =0;i<n;i++)
{
as
y = Integer.parseInt(bf.readLine());
a = y;
while(a!=0)
{
ak
x[a%10]++;
a/=10;
}
}
Pr
}
catch(IOException ie)
{}
catch(NumberFormatException nfe)
{}
rs
}
public void maxDigit()
{
he
{
max = i;
maxval = x[i];
}
Br
}
for(int i = 0;i<10;i++)
{
if (x[i] == maxval)
al
{
System.out.println(“Digit “ + i + “ is the most frequent.”);
}
oy
}
}
{
RepeatDigits rd = new RepeatDigits();
rd.readNos();
rd.maxDigit();
}
}
12 Goyal’s ICSE Computer Applications Specimen Question Paper with MTP Class 10