Solved 2016 Question Paper
ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications
Solved Question Papers
Section A
Question 1
(a) Define Encapsulation.
Answer
Encapsulation is a mechanism that binds together code and the data it manipulates. It keeps
them both safe from the outside world, preventing any unauthorised access or misuse. Only
member methods, which are wrapped inside the class, can access the data and other methods.
(b) What are keywords ? Give an example.
Answer
Keywords are reserved words that have a special meaning to the Java compiler. Example:
class, public, int, etc.
(c) Name any two library packages.
Answer
Two library packages are:
1. [Link]
2. [Link]
(d) Name the type of error ( syntax, runtime or logical error) in each case given below:
1. [Link] (36 – 45)
2. int a;b;c;
Answer
1. Runtime Error
2. Syntax Error
(e) If int x[] = { 4, 3, 7, 8, 9, 10}; what are the values of p and q ?
1
1. p = [Link]
2. q = x[2] + x[5] * x[1]
Answer
1. 6
2. q = x[2] + x[5] * x[1]
q = 7 + 10 * 3
q = 7 + 30
q = 37
Question 2
(a) State the difference between == operator and equals() method.
Answer
equals() ==
It is a method It is a relational operator
It is used to check if the contents of two strings It is used to check if two variables refer to the
are same or not same object in memory
Example: Example:
String s1 = new String("hello"); String s1 = new String("hello");
String s2 = new String("hello"); String s2 = new String("hello");
boolean res = [Link](s2); boolean res = s1 == s2;
[Link](res); [Link](res);
The output of this code snippet is true as The output of this code snippet is false as s1 and
contents of s1 and s2 are the same. s2 point to different String objects.
(b) What are the types of casting shown by the following examples:
1. char c = (char) 120;
2. int x = ‘t’;
Answer
1. Explicit Cast.
2. Implicit Cast.
(c) Differentiate between formal parameter and actual parameter.
Answer
2
Formal parameter Actual parameter
Actual parameters appear in function call
Formal parameters appear in function definition.
statement.
They represent the values received by the called They represent the values passed to the called
function. function.
(d) Write a function prototype of the following:
A function PosChar which takes a string argument and a character argument and
returns an integer value.
Answer
int PosChar(String s, char ch)
(e) Name any two types of access specifiers.
Answer
1. public
2. private
Question 3
(a) Give the output of the following string functions:
1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
2. "CABLE".compareTo("CADET")
Answer
1. 2 + 10 = 12
⇒ 66 - 68
2. ASCII Code of B - ASCII Code of D
⇒ -2
(b) Give the output of the following Math functions:
1. [Link](4.2)
2. [Link](-4)
Answer
1. 5.0
2. 4
(c) What is a parameterized constructor ?
3
Answer
A Parameterised constructor receives parameters at the time of creating an object and
initializes the object with the received values.
(d) Write down java expression for:
T=A2+B2+C2T=A2+B2+C2
Answer
T = [Link](a*a + b*b + c*c)
(e) Rewrite the following using ternary operator:
if (x%2 == 0)
[Link]("EVEN");
else
[Link]("ODD");
Answer
[Link](x%2 == 0 ? "EVEN" : "ODD");
(f) Convert the following while loop to the corresponding for loop:
int m = 5, n = 10;
while (n>=1)
{
[Link](m*n);
n--;
}
Answer
int m = 5;
for (int n = 10; n >= 1; n--) {
[Link](m*n);
}
(g) Write one difference between primitive data types and composite data types.
Answer
Primitive Data Types are built-in data types defined by Java language specification whereas
Composite Data Types are defined by the programmer.
(h) Analyze the given program segment and answer the following questions:
1. Write the output of the program segment.
2. How many times does the body of the loop gets executed ?
for(int m = 5; m <= 20; m += 5)
4
{ if(m % 3 == 0)
break;
else
if(m % 5 == 0)
[Link](m);
continue;
}
Answer
Output
5
10
Loop executes 3 times.
Below dry run of the loop explains its working.
m Output Remarks
5 5 1st Iteration
5
10 2nd Iteration
10
5
15 3rd Iteration — As m % 3 becomes true, break statement exists the loop.
10
(i) Give the output of the following expression:
a+= a++ + ++a + --a + a-- ; when a = 7
Answer
⇒ a = a + (a++ + ++a + --a + a--)
a+= a++ + ++a + --a + a--
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39
(j) Write the return type of the following library functions:
1. isLetterOrDigit(char)
2. replace(char, char)
Answer
1. boolean
5
2. String
Section B
Question 4
Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname — stores the name of the book
double price — stores the price of the book
Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on
the following criteria.
Price Discount
Less than or equal to ₹1000 2% of price
More than ₹1000 and less than or equal to ₹3000 10% of price
More than ₹3000 15% of price
(iv) void display() — To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
Answer
import [Link];
public class BookFair
{
private String bname;
private double price;
public BookFair() {
bname = "";
price = 0.0;
}
public void input() {
Scanner in = new Scanner([Link]);
[Link]("Enter name of the book: ");
6
bname = [Link]();
[Link]("Enter price of the book: ");
price = [Link]();
}
public void calculate() {
double disc;
if (price <= 1000)
disc = price * 0.02;
else if (price <= 3000)
disc = price * 0.1;
else
disc = price * 0.15;
price -= disc;
}
public void display() {
[Link]("Book Name: " + bname);
[Link]("Price after discount: " + price);
}
public static void main(String args[]) {
BookFair obj = new BookFair();
[Link]();
[Link]();
[Link]();
}
}
Output
Question 5
Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle [Given below]
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(b) To display the following pattern:
I
IC
7
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.
Answer
import [Link];
public class KboatPattern
{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Type 1 for Floyd's triangle");
[Link]("Type 2 for an ICSE pattern");
[Link]("Enter your choice: ");
int ch = [Link]();
switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](a++ + "\t");
}
[Link]();
}
break;
case 2:
String s = "ICSE";
for (int i = 0; i < [Link](); i++) {
for (int j = 0; j <= i; j++) {
[Link]([Link](j) + " ");
}
[Link]();
}
break;
default:
[Link]("Incorrect Choice");
}
}
}
Output
8
Question 6
Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-
versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.
Write a program to accept a word. Check and display whether the word is a palindrome or
only a special word or none of them.
Answer
import [Link];
public class KboatSpecialPalindrome
{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a word: ");
String str = [Link]();
str = [Link]();
int len = [Link]();
if ([Link](0) == [Link](len - 1)) {
boolean isPalin = true;
for (int i = 1; i < len / 2; i++) {
if ([Link](i) != [Link](len - 1 - i))
{
isPalin = false;
break;
}
}
if (isPalin) {
[Link]("Palindrome");
}
else {
[Link]("Special");
}
}
else {
[Link]("Neither Special nor
Palindrome");
}
}
}
9
Output
Question 7
Design a class to overload a function sumSeries() as follows:
(i) void sumSeries(int n, double x): with one integer argument and one double argument to
find and display the sum of the series given below:
s=x1−x2+x3−x4+x5... ... ... to n termss=1x−2x+3x−4x+5x... ... ... to n ter
ms
(ii) void sumSeries(): to find and display the sum of the following series:
s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)s=1+(1×2)+(1×2×3)+...
... ... +(1×2×3×4... ... ... ×20)
Answer
public class KboatOverload
{
void sumSeries(int n, double x) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double t = x / i;
if (i % 2 == 0)
sum -= t;
else
sum += t;
}
[Link]("Sum = " + sum);
}
void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
[Link]("Sum=" + sum);
}
}
Output
10
Question 8
Write a program to accept a number and check and display whether it is a Niven number or
not.
(Niven number is that number which is divisible by its sum of digits.).
Example:
Consider the number 126. Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.
Answer
import [Link];
public class KboatNivenNumber
{
public void checkNiven() {
Scanner in = new Scanner([Link]);
[Link]("Enter number: ");
int num = [Link]();
int orgNum = num;
int digitSum = 0;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
}
/*
* digitSum != 0 check prevents
* division by zero error for the
* case when users gives the number
* 0 as input
*/
if (digitSum != 0 && orgNum % digitSum == 0)
[Link](orgNum + " is a Niven number");
else
[Link](orgNum + " is not a Niven
number");
}
}
Output
Question 9
11
Write a program to initialize the seven Wonders of the World along with their locations in
two different arrays. Search for a name of the country input by the user. If found, display the
name of the country along with its Wonder, otherwise display "Sorry not found!".
Seven Wonders:
CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF CHINA,
MACHU PICCHU, PETRA, COLOSSEUM
Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Examples:
Country name: INDIA
Output: TAJ MAHAL
Country name: USA
Output: Sorry Not found!
Answer
import [Link];
public class Kboat7Wonders
{
public static void main(String args[]) {
String wonders[] = {"CHICHEN ITZA", "CHRIST THE
REDEEMER", "TAJMAHAL",
"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA",
"COLOSSEUM"};
String locations[] = {"MEXICO", "BRAZIL", "INDIA",
"CHINA", "PERU", "JORDAN",
"ITALY"};
Scanner in = new Scanner([Link]);
[Link]("Enter country: ");
String c = [Link]();
int i;
for (i = 0; i < [Link]; i++) {
if (locations[i].equals(c)) {
[Link](locations[i] + " - " +
wonders[i]);
break;
}
}
if (i == [Link])
[Link]("Sorry Not Found!");
}
12
}
13