Solved CompSci QP From 2010 2019 1735703705
Solved CompSci QP From 2010 2019 1735703705
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/k1V5R/year-
2010
2010
Section A
Question 1
Answer
Java compiler converts Java source code into an intermediate binary code called
Bytecode. Bytecode can't be executed directly on the processor. It needs to be converted
into Machine Code first.
Answer
The process of converting one predefined type into another is called type conversion. In
an implicit conversion, the result of a mixed mode expression is obtained in the higher
most data type of the variables without any intervention by the user. For example:
int a = 10;
float b = 25.5f, c;
c = a + b;
In case of explicit type conversion, the data gets converted to a type as specified by the
programmer. For example:
int a = 10;
double b = 25.5;
float c = (float)(a + b);
Answer
1/20
(d) What is Exception? Name two exception handling blocks.
Answer
An exception is an event, which occurs during the execution of a program, that disrupts
the normal flow of the program's instructions. Two exception handling blocks are try and
catch.
Answer
Question 2
(a) State the purpose and return data type of the following String functions:
1. indexOf()
2. compareTo()
Answer
1. indexOf() returns the index within the string of the first occurrence of the specified
character or -1 if the character is not present. Its return type is int.
2. compareTo() compares two strings lexicographically. Its return type is int.
(b) What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ * 2 + 3 * --x;
Answer
x = x++ * 2 + 3 * --x
⇒x=5*2+3*5
⇒ x = 10 + 15
⇒ x = 25
Answer
They are declared using keyword 'static'. They are declared without using keyword
'static'.
2/20
Static Data Members Non-Static Data Members
All objects of a class share the same Each object of the class gets its own copy
copy of Static data members. of Non-Static data members.
They can be accessed using the class They can be accessed only through an
name or object. object of the class.
Answer
length length()
It gives the length of an array i.e. the number of It gives the number of characters
elements stored in an array. present in a string.
Answer
Private members are only accessible inside the class in which they are defined and they
cannot be inherited by derived classes. Protected members are also only accessible
inside the class in which they are defined but they can be inherited by derived classes.
Question 3
(a) What do you understand by the term data abstraction? Explain with an example.
Answer
Data Abstraction refers to the act of representing essential features without including the
background details or explanations. A Switchboard is an example of Data Abstraction. It
hides all the details of the circuitry and current flow and provides a very simple way to
switch ON or OFF electrical appliances.
int m = 2;
int n = 15;
for(int i = 1; i < 5; i++);
m++;
--n;
System.out.println("m = " + m);
System.out.println("n = " + n);
Answer
Output
3/20
m=6
n=14
Explanation
As there are no curly braces after the for loop so only the statement m++; is inside the
loop. Loop executes 4 times so m becomes 6. The next statement --n; is outside the loop
so it is executed only once and n becomes 14.
char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);
Answer
Output
m = 97
Explanation
The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a'
that is assigned to m. But m is an int variable not a char variable. So, through implicit
conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.
(c) Analyze the following program segment and determine how many times the
loop will be executed and what will be the output of the program segment.
int k = 1, i = 2;
while(++i < 6)
k *= i;
System.out.println(k);
Answer
Output
60
Explanation
This table shows the change in values of i and k as while loop iterates:
i k Remarks
2 1 Initial values
3 3 1st Iteration
4 12 2nd Iteration
5 60 3rd Iteration
4/20
i k Remarks
Notice that System.out.println(k); is not inside while loop. As there are no curly
braces so only the statement k *= i; is inside the loop. The statement
System.out.println(k); is outside the while loop, it is executed once and prints value
of k which is 60 to the console.
(d) Give the prototype of a function check which receives a character ch and an
integer n and returns true or false.
Answer
Answer
Answer
1. Math.max(-17, -19)
2. Math.ceil(7.8)
Answer
1. -17
2. 8.0
Answer
A class can create objects of itself with different characteristics and common behaviour.
So, we can say that an Object represents a specific state of the class. For these reasons,
an Object is called an Instance of a Class.
5/20
(h)(ii) What is the use of the keyword import?
Answer
import keyword is used to import built-in and user-defined packages into our Java
program.
Section B
Question 4
Write a program to perform binary search on a list of integers given below, to search for
an element input by the user. If it is found display the element along with its position,
otherwise display the message "Search element not found".
Answer
import java.util.Scanner;
if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " + index);
}
}
}
6/20
Output
Question 5
Member methods:
7/20
Write a main method to create an object of a class and call the above member methods.
Answer
8/20
import java.util.Scanner;
public Student() {
name = "";
age = 0;
m1 = 0;
m2 = 0;
m3 = 0;
maximum = 0;
average = 0;
}
9/20
public void display() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Subject 1 Marks: " + m1);
System.out.println("Subject 2 Marks: " + m2);
System.out.println("Subject 3 Marks: " + m3);
System.out.println("Maximum Marks: " + maximum);
System.out.println("Average Marks: " + average);
}
Output
Question 6
10/20
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Write a program to input the name and ticket amount for the customer and calculate the
discount amount and net amount to be paid. Display the output in the following format for
each customer:
(Assume that there are 15 customers, first customer is given the serial no (SI. No.) 1, next
customer 2 …….. and so on)
Answer
11/20
import java.util.Scanner;
Output
12/20
Question 7
Write a menu driven program to accept a number from the user and check whether it is a
Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)
Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is contained in the
last digit(s) of its square.)
Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last
two digits.
Answer
13/20
import java.util.Scanner;
switch (choice) {
case 1:
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
c++;
}
}
if (c == 2)
System.out.println(num + " is Prime");
else
System.out.println(num + " is not Prime");
break;
case 2:
int numCopy = num;
int sq = num * num;
int d = 0;
/*
* Count the number of
* digits in num
*/
while(num > 0) {
d++;
num /= 10;
}
/*
* Extract the last d digits
* from square of num
*/
int ld = (int)(sq % Math.pow(10, d));
if (ld == numCopy)
System.out.println(numCopy + " is automorphic");
else
System.out.println(numCopy + " is not automorphic");
break;
default:
System.out.println("Incorrect Choice");
break;
14/20
}
}
}
Output
Question 8
P[ ] Q[ ] R[ ]
15/20
Input Input Output
4 19 4
6 23 6
1 7 1
2 8 2
3 3
10 10
19
23
Answer
16/20
import java.util.Scanner;
i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}
int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}
Output
17/20
Question 9
Write a program to input a sentence. Count and display the frequency of each letter of the
sentence in alphabetical order.
Sample Input: COMPUTER APPLICATIONS
Sample Output:
A 2 O 2
C 2 P 3
I 1 R 1
L 2 S 1
M 1 T 2
N 1 U 1
Answer
18/20
import java.util.Scanner;
System.out.println("Character\tFrequency");
for (int i = 0; i < freqMap.length; i++) {
if (freqMap[i] > 0) {
System.out.println((char)(i + 65)
+ "\t\t" + freqMap[i]);
}
}
}
}
Output
19/20
20/20
Solved 2011 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/n65x7/year-2011
2011
Section A
Question 1
Answer
A class is a blue print that represents a set of objects that share common characteristics
and behaviour whereas an object is a specific instance of a class having a specific
identity, specific characteristics and specific behaviour.
(b) What does the token 'keyword' refer to in the context of Java? Give an example
for keyword.
Answer
Keywords are reserved words that have a special meaning for the Java compiler. Java
compiler reserves these words for its own use so Keywords cannot be used as identifiers.
An example of keyword is class.
(c) State the difference between entry controlled loop and exit controlled loop.
Answer
It checks the condition at the time of It checks the condition after executing its body. If
entry. Only if the condition is true, the condition is true, loop will perform the next
the program control enters the body iteration otherwise program control will move out
of the loop. of the loop.
Loop does not execute at all if the The loop executes at least once even if the
condition is false. condition is false.
1/18
Answer
1. Pass by value.
2. Pass by reference.
Answer
/ %
Returns the quotient of division operation Returns the remainder of division operation
Example: int a = 5 / 2; Here a will get the Example: int b = 5 % 2; Here b will get the
value of 2 which is the quotient of this value of 1 which is the remainder of this
division operation division operation
Question 2
(a) State the total size in bytes, of the arrays a[4] of char data type and p[4] of float
data type.
Answer
Answer
(i) java.util
(ii) Constructor
Answer
Output
ComputerApplications
true
2/18
Explanation
n.substring(0,8) returns the substring of n starting at index 0 till 7 (i.e. 8 - 1 = 7) which is
"Computer". m.substring(9) returns the substring of m starting at index 9 till the end of the
string which is "Applications". concat() method joins "Computer" and "Applications"
together to give the output as ComputerApplications.
1. System.out.println(Character.isUpperCase('R'));
2. System.out.println(Character.toUpperCase('j'));
Answer
1. true
2. J
Answer
The keyword 'void' signifies that the function doesn't return a value to the calling function.
Question 3
(a) Analyze the following program segment and determine how many times the
loop will be executed and what will be the output of the program segment?
int p = 200;
while(true){
if(p < 100)
break;
p = p - 20;
}
System.out.println(p);
Answer
Output
80
Explanation
p Remarks
3/18
p Remarks
80 6th Iteration. Now p < 100 becomes true so break statement is executed
terminating the loop.
(i)
int k = 5, j = 9;
k += k++ - ++j + k;
System.out.println("k = " + k);
System.out.println("j = " + j);
(ii)
double b = -15.6;
double a = Math.rint(Math.abs(b));
System.out.println("a = " + a);
Answer
(i)
Output
k = 6
j = 10
Explanation
k += k++ - ++j + k
⇒ k = 5 + (5 - 10 + 6)
⇒k=5+1
⇒k=6
++j increments j to 10
(ii)
Output
16.0
Explanation
Math.abs(-15.6) gives 15.6. Math.rint(15.6) gives 16.0.
4/18
Answer
Constructor overloading is a technique in Java through which a class can have more than
one constructor with different parameter lists. The different constructors of the class are
differentiated by the compiler using the number of parameters in the list and their types.
For example, the Rectangle class below has two constructors:
class Rectangle {
int length;
int breadth;
//Constructor 1
public Rectangle() {
length = 0;
breadth = 0;
}
//Constructor 2
public Rectangle(int l, int b) {
length = l;
breadth = b;
}
//Constructor 2 called
Rectangle obj2 = new Rectangle(10, 15);
}
}
(d) Give the prototype of a function search which receives a sentence 'sent' and
word 'w' and returns 1 or 0.
Answer
z=x+y5x3+2y
Answer
z = (5 * x * x * x + 2 * y) / (x + y)
Answer
5/18
1. System.out.println(s.lastIndexOf(" "));
2. double num = Double.parseDouble(x);
Answer
1. throws IOException
2. static
Answer
Java Library classes are a set of predefined classes in the form of packages that are
provided to the programmer as part of Java installation. Library classes simplify the job of
programmers by providing built-in methods for common and non-trivial tasks like taking
input from user, displaying output to user, etc. For example, System class in java.lang
package of Java Library classes provides the print() and println() methods for displaying
output to user.
(i) Write one difference between Linear Search and Binary Search.
Answer
Linear search works on unsorted as well as sorted arrays whereas Binary search works
on only sorted arrays.
Section B
Question 4
int days To store the number of days the bike is taken on rent
6/18
Member Methods Purpose
Days Charge
Output:
Answer
7/18
import java.util.Scanner;
Output
8/18
Question 5
Write a program to input and sort the weight of ten people. Sort and display them in
descending order using the selection sort technique.
Answer
9/18
import java.util.Scanner;
double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}
Output
Question 6
10/18
Write a program to input a number and print whether the number is a special number or
not.
(A number is said to be a special number, if the sum of the factorial of the digits of the
number is same as the original number).
Example:
145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.
(Where ! stands for factorial of the number and the factorial value of a number is the
product of all integers from 1 to that number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)
Answer
import java.util.Scanner;
int t = num;
int sum = 0;
while (t != 0) {
int d = t % 10;
sum += fact(d);
t /= 10;
}
if (sum == num)
System.out.println(num + " is a special number");
else
System.out.println(num + " is not a special number");
}
}
Output
11/18
Question 7
Write a program to accept a word and convert it into lower case, if it is in upper case.
Display the new word by replacing only the vowels with the letter following it.
Sample Input: computer
Sample Output: cpmpvtfr
Answer
12/18
import java.util.Scanner;
if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {
}
else {
newStr = newStr + ch;
}
}
System.out.println(newStr);
}
}
Output
13/18
Question 8
1. void compare(int, int) — to compare two integers values and print the greater of the
two integers.
2. void compare(char, char) — to compare the numeric value of two characters and
print with the higher numeric value.
3. void compare(String, String) — to compare the length of the two strings and print
the longer of the two.
Answer
14/18
import java.util.Scanner;
if (a > b) {
System.out.println(a);
}
else {
System.out.println(b);
}
if (x > y) {
System.out.println(a);
}
else {
System.out.println(b);
}
int l1 = a.length();
int l2 = b.length();
15/18
in.nextLine();
obj.compare(c1, c2);
Output
Question 9
Write a menu driven program to perform the following tasks by using Switch case
statement:
Answer
16/18
import java.util.Scanner;
switch (choice) {
case 1:
System.out.print("Enter n: ");
int n = in.nextInt();
for (int i = 1; i <= n; i++)
System.out.print(((i * i) - 1) + " ");
System.out.println();
break;
case 2:
double sum = 0;
for (int i = 1; i <= 19; i = i + 2)
sum += i / (double)(i + 1);
System.out.println("Sum = " + sum);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
Output
17/18
18/18
Solved 2012 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/n0oZm/year-
2012
2012
Section A
Question 1
(a) Give one example each of a primitive data type and a composite data type.
Answer
1. int
2. array
(b) Give one point of difference between unary and binary operators.
Answer
unary operators operate on a single operand whereas binary operators operate on two
operands.
(c) Differentiate between call by value or pass by value and call by reference or
pass by reference.
Answer
Changes made to formal parameters are Changes made to formal parameters are
not reflected back to actual parameters. reflected back to actual parameters.
2as+u2
Answer
Math.sqrt(2 * a * s + u * u)
1/17
(e) Name the type of error (syntax, runtime or logical error) in each case given
below:
Answer
1. Runtime error
2. Logical error
3. syntax error
Question 2
(a) Create a class with one integer instance variable. Initialize the variable using:
1. default constructor
2. parameterized constructor
Answer
class Number {
int a;
public Number() {
a = 0;
}
public Number(int x) {
a = x;
}
}
Answer
Answer
An array is a structure to store a number of values of the same data type in contiguous
memory locations. The following statement declares an integer array of 10 elements:
2/17
1. Makes several passes through the array, selecting the next smallest item in
the array each time and placing it where it belongs in the array.
2. At each stage, compares the sought key value with the key value of the
middle element of the array.
Answer
1. Selection Sort
2. Binary Search
(e) Differentiate between public and private modifiers for members of a class.
Answer
public modifier makes the class members accessible both within and outside their class
whereas private modifier makes the class members accessible only within the class in
which they are declared.
Question 3
(a) What are the values of x and y when the following statements are executed?
Answer
Output
x = true
y = 36
Explanation
The ternary operator (a > b)? true : false returns true as its condition a > b is true so
it returns its first expression that is true.
The ternary operator (a < b)? a : b returns b as its condition a < b is false so it returns
its second expression that is b. Value of b is 36 so y also becomes 36.
char c = 'A';
int n = c + 1;
char ch = (char)n;
Answer
Value of n is 66 and ch is B.
int n = c + 1, here due to implicit conversion, 'A' will be converted to its ASCII value 65. 1
is added to it making the value of n 66.
3/17
char ch = (char)n, here through explicit conversion 66 is converted to its corresponding
character that is 'B' so value of ch becomes B.
(c) What will be the result stored in x after evaluating the following expression?
int x = 4;
x += (x++) + (++x) + x;
Answer
x += (x++) + (++x) + x
⇒ x = x + ((x++) + (++x) + x)
⇒ x = 4 + (4 + 6 + 6)
⇒ x = 4 + 16
⇒ x = 20
Answer
Output
2.0
3.0
Explanation
Math.floor(2.9) gives 2.0. Math.min(2.0, 2.5) gives 2.0.
String s = "Examination";
int n = s.length();
System.out.println(s.startsWith(s.substring(5, n)));
System.out.println(s.charAt(2) == s.charAt(6));
Answer
Output
false
true
Explanation
Putting the value of n in s.substring(5, n), it becomes s.substring(5, 11). This gives
"nation". As s does not start with "nation" so s.startsWith(s.substring(5, n)) returns false.
4/17
(f) State the method that:
Answer
1. Float.parseFloat()
2. Character.isUpperCase()
(g) State the data type and values of a and b after the following segment is
executed:
Answer
Data type of a is int and value is 2. Data type of b is boolean and value is false.
String s = "malayalam";
System.out.println(s.indexOf('m'));
System.out.println(s.lastIndexOf('m'));
Answer
Output
0
8
Explanation
The first m appears at index 0 and the last m appears at index 8.
(i) 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);
}
Answer
int f = 1, i;
while (i <= 5) {
f *= i;
System.out.println(f);
i++;
}
5/17
(j) In the program given below, state the name and the value of the:
class MyClass{
static int x = 7;
int y = 2;
public static void main(String args[]){
MyClass obj = new MyClass();
System.out.println(x);
obj.sampleMethod(5);
int a = 6;
System.out.println(a);
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
}
Answer
Section B
Question 4
Member methods:
1. void input() — To input and store the accession number, title and author.
2. void compute() — To accept the number of days late, calculate and display the fine
charged at the rate of Rs. 2 per day.
3. void display() — To display the details in the following format:
6/17
Write a main method to create an object of the class and call the above member
methods.
Answer
import java.util.Scanner;
void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter book title: ");
title = in.nextLine();
System.out.print("Enter author: ");
author = in.nextLine();
System.out.print("Enter accession number: ");
accNum = in.nextInt();
}
void compute() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of days late: ");
int days = in.nextInt();
int fine = days * 2;
System.out.println("Fine = Rs." + fine);
}
void display() {
System.out.println("Accession Number\tTitle\tAuthor");
System.out.println(accNum + "\t\t" + title + "\t" + author);
}
Output
7/17
Question 5
Given below is a hypothetical table showing rates of income tax for male citizens below
the age of 65 years:
Is greater than Rs. 1,60,000 and less than or equal to Rs. (TI - 1,60,000) x 10%
5,00,000.
Is greater than Rs. 5,00,000 and less than or equal to Rs. [(TI - 5,00,000) x 20%] +
8,00,000 34,000
Write a program to input the age, gender (male or female) and Taxable Income of a
person.
If the age is more than 65 years or the gender is female, display “wrong category”. If the
age is less than or equal to 65 years and the gender is male, compute and display the
income tax payable as per the table given above.
Answer
8/17
import java.util.Scanner;
Output
9/17
Question 6
Write a program to accept a string. Convert the string into upper case letters. Count and
output the number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4
Answer
import java.util.Scanner;
}
}
Output
10/17
Question 7
1. void polygon(int n, char ch) — with one integer and one character type argument to
draw a filled square of side n using the character stored in ch.
2. void polygon(int x, int y) — with two integer arguments that draws a filled rectangle
of length x and breadth y, using the symbol '@'.
3. void polygon() — with no argument that draws a filled triangle shown below:
Example:
Answer
11/17
public class KboatPolygon
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}
Output
12/17
Question 8
Answer
13/17
import java.util.Scanner;
switch (ch) {
case 1:
int a = 0, b = 1;
System.out.print(a + " " + b);
for (int i = 3; i <= 10; i++) {
int term = a + b;
System.out.print(" " + term);
a = b;
b = term;
}
break;
case 2:
System.out.print("Enter number: ");
int num = in.nextInt();
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("Sum of Digits " + " = " + sum);
break;
default:
System.out.println("Incorrect choice");
break;
}
}
}
Output
14/17
Question 9
Write a program to accept the names of 10 cities in a single dimensional string array and
their STD (Subscribers Trunk Dialling) codes in another single dimension integer array.
Search for the name of a city input by the user in the list. If found, display "Search
Successful" and print the name of the city along with its STD code, or else display the
message "Search unsuccessful, no such city in the list".
Answer
15/17
import java.util.Scanner;
int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}
Output
16/17
17/17
Solved 2013 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/nRm4n/year-
2013
2013
Section A
Question 1
Answer
Precedence of operators refers to the order in which the operators are applied to the
operands in an expression.
Answer
Literals are data items that are fixed data values. Java provides different types of literals
like:
1. Integer Literals
2. Floating-Point Literals
3. Boolean Literals
4. Character Literals
5. String Literals
6. null Literal
Answer
1. Inheritance
2. Abstraction
1/18
Answer
Constructor has the same name as class name whereas function should have a different
name than class name.
(e) What are the types of casting shown by the following examples?
1. double x = 15.2;
int y = (int) x;
2. int x = 12;
long y = x;
Answer
Question 2
Answer
1. Integer
2. Character
(b) What is the difference between a break statement and a continue statement
when they occur in a loop?
Answer
When the break statement gets executed, it terminates its loop completely and control
reaches to the statement immediately following the loop. The continue statement
terminates only the current iteration of the loop by skipping rest of the statements in the
body of the loop.
(c) Write statements to show how finding the length of a character array char[]
differs from finding the length of a String object str.
Answer
2/18
String str = "Test";
int len = str.length();
Answer
1. void
2. this
Answer
Question 3
Answer
(b) State the values stored in the variables str1 and str2:
String s1 = "good";
String s2 = "world matters";
String str1 = s2.substring(5).replace('t', 'n');
String str2 = s1.concat(str1);
Answer
Value stored in str1 is " manners" and str2 is "good manners". (Note that str1 begins with
a space.)
Explanation
s2.substring(5) gives a substring from index 5 till the end of the string which is " matters".
The replace method replaces all 't' in " matters" with 'n' giving " manners". s1.concat(str1)
joins together "good" and " manners" so "good manners" is stored in str2.
Answer
(d) Rewrite the following program segment using the if..else statement:
3/18
comm = (sale > 15000)? sale * 5 / 100 : 0;
Answer
(e) How many times will the following loop execute? What value will be returned?
int x = 2, y = 50;
do{
++x;
y -= x++;
}while(x <= 10);
return y;
Answer
The loop will run 5 times and the value returned is 15.
(f) What is the data type that the following library functions return?
1. isWhitespace(char ch)
2. Math.random()
Answer
1. boolean
2. double
ut+21ft2
Answer
u * t + 1 / 2.0 * f * t * t
(h) If int n[] = {1, 2, 3, 5, 7, 9, 13, 16}, what are the values of x and y?
x = Math.pow(n[4], n[2]);
y = Math.sqrt(n[5] + n[7]);
Answer
x = Math.pow(n[4], n[2]);
⇒ x = Math.pow(7, 3);
⇒ x = 343.0;
4/18
y = Math.sqrt(n[5] + n[7]);
⇒ y = Math.sqrt(9 + 16);
⇒ y = Math.sqrt(25);
⇒ y = 5.0;
(i) What is the final value of ctr when the iteration process given below, executes?
int ctr = 0;
for(int i = 1; i <= 5; i++)
for(int j = 1; j <= 5; j += 2)
++ctr;
Answer
The outer loop executes 5 times. For each iteration of outer loop, the inner loop executes
3 times. So the statement ++ctr; is executed a total of 5 x 3 = 15 times.
Answer
1. nextInt()
2. nextLine()
Section B
Question 4
String flavour stores the flavour of the juice (e.g., orange, apple, etc.)
String pack_type stores the type of packaging (e.g., tera-pack, PET bottle, etc.)
int pack_size stores package size (e.g., 200 mL, 400 mL, etc.)
Member
Methods Purpose
5/18
Member
Methods Purpose
void input() to input and store the product code, flavour, pack type, pack size and
product price
void display() to display the product code, flavour, pack type, pack size and product
price
Answer
6/18
import java.util.Scanner;
public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}
Output
7/18
Question 5
The International Standard Book Number (ISBN) is a unique numeric book identifier
which is printed on every book. The ISBN is based upon a 10-digit code.
Example:
For an ISBN 1401601499
Sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4 + 9 × 9 + 10 × 9 = 253
which is divisible by 11.
Answer
8/18
import java.util.Scanner;
if (count != 10) {
System.out.println("Illegal ISBN");
}
else if (sum % 11 == 0) {
System.out.println("Legal ISBN");
}
else {
System.out.println("Illegal ISBN");
}
}
}
Output
9/18
Question 6
Write a program that encodes a word into Piglatin. To translate word into Piglatin word,
convert the word into uppercase and then place the first vowel of the original word as the
start of the new word along with the remaining alphabets. The alphabets present before
the vowel being shifted towards the end followed by "AY".
Answer
10/18
import java.util.Scanner;
word=word.toUpperCase();
String piglatin="";
int flag=0;
if(flag == 0)
{
piglatin = word + "AY";
}
System.out.println(word + " in Piglatin format is " + piglatin);
}
}
Output
11/18
Question 7
Write a program to input 10 integer elements in an array and sort them in descending
order using bubble sort technique.
Answer
12/18
import java.util.Scanner;
//Bubble Sort
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] < arr[j + 1]) {
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
System.out.println("Sorted Array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output
13/18
Question 8
1. double series(double n) with one double argument and returns the sum of the
series.
sum = (1/1) + (1/2) + (1/3) + .......... + (1/n)
2. 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
Answer
14/18
public class KboatSeries
{
double series(double n) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double term = 1.0 / i;
sum += term;
}
return sum;
}
Output
Question 9
15/18
1. To check and display whether a number input by the user is a composite number or
not.
A number is said to be composite, if it has one or more than one factors excluding 1
and the number itself.
Example: 4, 6, 8, 9...
2. To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
Answer
16/18
import java.util.Scanner;
switch (ch) {
case 1:
System.out.print("Enter Number: ");
int n = in.nextInt();
int c = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0)
c++;
}
if (c > 2)
System.out.println("Composite Number");
else
System.out.println("Not a Composite Number");
break;
case 2:
System.out.print("Enter Number: ");
int num = in.nextInt();
int s = 10;
while (num != 0) {
int d = num % 10;
if (d < s)
s = d;
num /= 10;
}
System.out.println("Smallest digit is " + s);
break;
default:
System.out.println("Wrong choice");
}
}
}
Output
17/18
18/18
Solved 2014 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/nq88K/year-2014
2014
Section A
Question 1
1. /*comment*/
2. /*comment
3. //comment
4. */comment*/
Answer
Option 1 — /*comment*/
Option 3 — //comment
(b) What is meant by a package ? Name any two java Application Programming
Interface packages.
Answer
A package is a named collection of Java classes that are grouped on the basis of their
functionality. Two java Application Programming Interface packages are:
1. java.util
2. java.io
1. a 64-bit integer and is used when you need a range of values wider than those
provided by int.
2. a single 16-bit Unicode character whose default value is '\u0000'.
Answer
1. long
1/17
2. char
(d) State one difference between the floating point literals float and double.
Answer
float literals have a size of 32 bits so they double literals have a size of 64 bits so
can store a fractional number with around they can store a fractional number with
6-7 total digits of precision. 15-16 total digits of precision.
(e) Find the errors in the given program segment and re-write the statements
correctly to assign values to an integer array.
Answer
Corrected Code:
Question 2
(a) Operators with higher precedence are evaluated before operators with relatively
lower precedence. Arrange the operators given below in order of higher
precedence to lower precedence:
1. &&
2. %
3. >=
4. ++
Answer
++
%
>=
&&
1. System.out.println("Java");
2. costPrice = 457.50;
3. Car hybrid = new Car();
2/17
4. petrolPrice++;
Answer
1. Method Invocation
2. Assignment
3. Object Creation
4. Increment
(c) Give two differences between the switch statement and the if-else statement
Answer
switch if-else
switch can only test if the if-else can test for any boolean expression like
expression is equal to any of its less than, greater than, equal to, not equal to,
case constants etc.
Answer
A loop which continues iterating indefinitely and never stops is termed as infinite loop.
Below is an example of infinite loop:
for (;;)
System.out.println("Infinite Loop");
Answer
A constructor is a member method that is written with the same name as the class name
and is used to initialize the data members or instance variables. A constructor does not
have a return type. It is invoked at the time of creating any object of the class.
Question 3
(a) List the variables from those given below that are composite data types:
1. static int x;
2. arr[i]=10;
3. obj.display();
4. boolean b;
5. private char chr;
6. String str;
3/17
Answer
arr[i]=10;
obj.display();
String str;
Answer
grinds
WHEAT
Explanation:
(c) What are the final values stored in variable x and y below?
double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b));
Answer
Explanation:
(d) Rewrite the following program segment using if-else statements instead of the
ternary operator:
Answer
4/17
String grade;
if (marks >= 90)
grade = "A";
else if (marks >= 80)
grade = "B";
else
grade = "C";
Answer
Output
6
4
Explanation
1. a++ increments value of a by 1 so a becomes 6.
2. a -= (a--) - (--a)
⇒ a = a - ((a--) - (--a))
⇒ a = 6 - (6 - 4)
⇒a=6-2
⇒a=4
1. compareTo()
2. equals()
Answer
1. int
2. boolean
(g) State the value of characteristic and mantissa when the following code is
executed:
String s = "4.3756";
int n = s.indexOf('.');
int characteristic=Integer.parseInt(s.substring(0,n));
int mantissa=Integer.valueOf(s.substring(n+1));
Answer
5/17
Index of . in String s is 1 so variable n is initialized to 1. s.substring(0,n) gives 4.
Integer.parseInt() converts string "4" into integer 4 and this 4 is assigned to the variable
characteristic.
s.substring(n+1) gives 3756 i.e. the string starting at index 2 till the end of s.
Integer.valueOf() converts string "3756" into integer 3756 and this value is assigned to the
variable mantissa.
Answer
1. Name the variables for which each object of the class will have its own
distinct copy.
2. Name the variables that are common to all objects of the class.
Answer
1. a, b
2. x, y
(j) What will be the output when the following code segments are executed?
(i)
String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x="+x);
System.out.println("y="+y);
(ii)
6/17
Answer
x=1001
y=1001.0
Section B
Question 4
Member
Methods Purpose
void display() To display the title of the movie and a message based on the rating as
per the table given below
Ratings Table
Write a main method to create an object of the class and call the above member
methods.
7/17
Answer
import java.util.Scanner;
public movieMagic() {
year = 0;
title = "";
rating = 0.0f;
}
System.out.println(title);
System.out.println(message);
}
Output
8/17
Question 5
A special two-digit number is such that when the sum of its digits is added to the product
of its digits, the result is equal to the original two-digit number.
Write a program to accept a two-digit number. Add the sum of its digits to the product of
its digits. If the value is equal to the number input, then display the message "Special two
—digit number" otherwise, display the message "Not a special two-digit number".
Answer
9/17
import java.util.Scanner;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");
}
}
Output
10/17
Question 6
Write a program to assign a full path and file name as given below. Using library
functions, extract and output the file path, file name and file extension separately as
shown.
Input
C:\Users\admin\Pictures\flower.jpg
Output
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
Answer
11/17
import java.util.Scanner;
Output
Question 7
1. double area (double a, double b, double c) with three double arguments, returns the
area of a scalene triangle using the formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2
12/17
2. double area (int a, int b, int height) with three integer arguments, returns the area of
a trapezium using the formula:
area = (1/2)height(a + b)
3. double area (double diagonal1, double diagonal2) with two double arguments,
returns the area of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)
Answer
import java.util.Scanner;
Output
Question 8
Using the switch statement, write a menu driven program to calculate the maturity amount
of a Bank Deposit.
The user is given the following options:
1. Term Deposit
2. Recurring Deposit
For option 1, accept principal (P), rate of interest(r) and time period in years(n). Calculate
and output the maturity amount(A) receivable using the formula:
A = P[1 + r / 100]n
For option 2, accept Monthly Installment (P), rate of interest (r) and time period in months
(n). Calculate and output the maturity amount (A) receivable using the formula:
A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12
13/17
For an incorrect option, an appropriate error message should be displayed.
Answer
import java.util.Scanner;
switch (ch) {
case 1:
System.out.print("Enter Principal: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in years: ");
n = in.nextInt();
a = p * Math.pow(1 + r / 100, n);
System.out.println("Maturity amount = " + a);
break;
case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;
default:
System.out.println("Invalid choice");
}
}
}
Output
14/17
15/17
Question 9
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:
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010
Answer
16/17
import java.util.Scanner;
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
Output
17/17
Solved 2015 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/zpDOM/year-
2015
2015
Section A
Question 1
(a) What are the default values of the primitive data type int and float?
Answer
Answer
1. Encapsulation
2. Inheritance
Answer
Identifiers are symbolic names given to different parts of a program such as variables,
methods, classes, objects, etc.
Answer
1. Real Literal
2. Character Literal
3. Boolean Literal
4. String Literal
(e) Name the wrapper classes of char type and boolean type.
Answer
1/17
Wrapper class of char type is Character and boolean type is Boolean.
Question 2
Answer
int n = (q – p) > (p – q) ? (q – p) : (p – q)
⇒ int n = (19 - 5) > (5 - 19) ? (19 - 5) : (5 - 19)
⇒ int n = 14 > -14 ? 14 : -14
⇒ int n = 14 [∵ 14 > -14 is true so ? : returns 14]
Final value of n is 14
(b) Arrange the following primitive data types in an ascending order of their size:
Answer
Answer
Answer
(e) What are the values of a and b after the following function is executed, if the
values passed are 30 and 50:
Answer
2/17
Value of a is 50 and b is 30.
Output of the code is:
50,30
Question 3
(a) State the data type and value of y after the following is executed:
char x='7';
y=Character.isLetter(x);
Answer
Data type of y is boolean and value is false. Character.isLetter() method checks if its
argument is a letter or not and as 7 is a number not a letter hence it returns false.
(b) What is the function of catch block in exception handling ? Where does it
appear in a program ?
Answer
Catch block contains statements that we want to execute in case an exception is thrown
in the try block. Catch block appears immediately after the try block in a program.
(c) State the output when the following program segment is executed:
Answer
art
true
Explanation
a.substring(2, 5) extracts the characters of string a starting from index 2 till index 4. So h
contains the string "art". b.substring(8) extracts characters of b from index 8 till the end so
it returns "Art". toUpperCase() converts it into uppercase. Thus string "ART" gets
assigned to k. Values of h and k are "art" and "ART", respectively. As both h and k differ in
case only hence equalsIgnoreCase returns true.
(d) The access specifier that gives the most accessibility is ________ and the least
accessibility is ________.
Answer
3/17
The access specifier that gives the most accessibility is public and the least accessibility
is private.
(e) (i) Name the mathematical function which is used to find sine of an angle given
in radians.
(ii) Name a string function which removes the blank spaces provided in the prefix
and suffix of a string.
Answer
1. 0
2. value stored in arr[0]
3. 0000
4. garbage value
Answer
(ii) Name the keyword which is used- to resolve the conflict between method
parameter and instance variables/fields.
Answer
this keyword
1. BufferedReader
2. Scanner
Answer
1. java.io
2. java.util
4/17
char ch ;
int x=97;
do
{
ch=(char)x;
System.out.print(ch + " " );
if(x%10 == 0)
break;
++x;
} while(x<=100);
Answer
The output of the above code is:
a b c d
Explanation
The below table shows the dry run of the program:
x ch Output Remarks
97 a a 1st Iteration
98 b ab 2nd Iteration
2aba2+b2
Answer
(a * a + b * b) / (2 * a * b)
Answer
Section B
Question 4
5/17
Instance variables/data members:
int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking lot.
double bill — To store the bill amount.
Member Methods:
void input() — To input and store the vno and hours.
void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or
part thereof, and ₹1.50 for each additional hour or part thereof.
void display() — To display the detail.
Write a main() method to create an object of the class and call the above methods.
Answer
import java.util.Scanner;
Output
6/17
Question 5
Write two separate programs to generate the following patterns using iteration (loop)
statements:
(a)
*
* #
* # *
* # * #
* # * # *
(b)
54321
5432
543
54
5
Answer
7/17
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
Output
Output
8/17
Question 6
Write a program to input and store roll numbers, names and marks in 3 subjects of n
number of students in five single dimensional arrays and display the remark based on
average marks as given below:
85 — 100 Excellent
75 — 84 Distinction
60 — 74 First Class
40 — 59 Pass
Answer
9/17
import java.util.Scanner;
System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) {
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}
}
}
Output
10/17
11/17
Question 7
1. void Joystring(String s, char ch1, char ch2) with one string argument and two
character arguments that replaces the character argument ch1 with the character
argument ch2 in the given String s and prints the new string.
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"
12/17
2. void Joystring(String s) with one string argument that prints the position of the first
space and the last space of the given String s.
Example:
Input value of s = "Cloud computing means Internet based computing"
Output:
First index: 5
Last Index: 36
3. void Joystring(String s1, String s2) with two string arguments that combines the two
strings with a space between them and prints the resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES
Answer
Output
13/17
Question 8
Write a program to input twenty names in an array. Arrange these names in descending
order of letters, using the bubble sort technique.
Answer
import java.util.Scanner;
//Bubble Sort
for (int i = 0; i < names.length - 1; i++) {
for (int j = 0; j < names.length - 1 - i; j++) {
if (names[j].compareToIgnoreCase(names[j + 1]) < 0) {
String temp = names[j + 1];
names[j + 1] = names[j];
names[j] = temp;
}
}
}
System.out.println("\nSorted Names");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}
}
14/17
Output
Question 9
15/17
(ii) To find and display the factorial of a number input by the user (the factorial of a non-
negative integer n, denoted by n!, is the product of all integers less than or equal to n.)
Example:
Sample Input : n = 5
Sample Output : 5! = 1*2*3*4*5 = 120
Answer
import java.util.Scanner;
switch (choice) {
case 1:
System.out.print("Enter number: ");
num = in.nextInt();
for (int i = 1; i < num; i++) {
if (num % i == 0) {
System.out.print(i + " ");
}
}
System.out.println();
break;
case 2:
System.out.print("Enter number: ");
num = in.nextInt();
int f = 1;
for (int i = 1; i <= num; i++)
f *= i;
System.out.println("Factorial = " + f);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
Output
16/17
17/17
Solved 2016 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/qM0BW/year-
2016
2016
Section A
Question 1
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.
Answer
Keywords are reserved words that have a special meaning to the Java compiler.
Example: class, public, int, etc.
Answer
1. java.io
2. java.util
(d) Name the type of error ( syntax, runtime or logical error) in each case given
below:
Answer
1/19
1. Runtime Error
2. Syntax Error
1. p = x.length
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
Answer
equals() ==
It is used to check if the contents of two It is used to check if two variables refer to
strings are same or not the 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 = s1.equals(s2); boolean res = s1 == s2;
System.out.println(res); System.out.println(res);
The output of this code snippet is true as The output of this code snippet is false as
contents of s1 and s2 are the same. s1 and s2 point to different String objects.
(b) What are the types of casting shown by the following examples:
Answer
1. Explicit Cast.
2. Implicit Cast.
Answer
2/19
Formal parameter Actual parameter
They represent the values received by the They represent the values passed to the
called function. called function.
Answer
Answer
1. public
2. private
Question 3
1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
2. "CABLE".compareTo("CADET")
Answer
1. 2 + 10 = 12
2. ASCII Code of B - ASCII Code of D
⇒ 66 - 68
⇒ -2
1. Math.ceil(4.2)
2. Math.abs(-4)
Answer
1. 5.0
2. 4
Answer
3/19
A Parameterised constructor receives parameters at the time of creating an object and
initializes the object with the received values.
T=A2+B2+C2
Answer
if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
Answer
(f) Convert the following while loop to the corresponding for loop:
int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n--;
}
Answer
int m = 5;
for (int n = 10; n >= 1; n--) {
System.out.println(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:
4/19
for(int m = 5; m <= 20; m += 5)
{ if(m % 3 == 0)
break;
else
if(m % 5 == 0)
System.out.println(m);
continue;
}
Answer
Output
5
10
m Output Remarks
5 5 1st Iteration
10 5 2nd Iteration
10
Answer
1. isLetterOrDigit(char)
2. replace(char, char)
Answer
1. boolean
2. String
5/19
Section B
Question 4
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
More than ₹1000 and less than or equal to ₹3000 10% 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
6/19
import java.util.Scanner;
public BookFair() {
bname = "";
price = 0.0;
}
price -= disc;
}
Output
7/19
Question 5
Using the switch statement, write a menu driven program for the following:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Answer
8/19
import java.util.Scanner;
switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;
case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;
default:
System.out.println("Incorrect Choice");
}
}
}
Output
9/19
10/19
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
11/19
import java.util.Scanner;
if (isPalin) {
System.out.println("Palindrome");
}
else {
System.out.println("Special");
}
}
else {
System.out.println("Neither Special nor Palindrome");
}
}
}
Output
12/19
Question 7
(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:
(ii) void sumSeries(): to find and display the sum of the following series:
Answer
13/19
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;
}
System.out.println("Sum = " + sum);
}
void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
System.out.println("Sum=" + sum);
}
}
Output
14/19
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
15/19
import java.util.Scanner;
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)
System.out.println(orgNum + " is a Niven number");
else
System.out.println(orgNum + " is not a Niven number");
}
}
Output
16/19
Question 9
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
Answer
17/19
import java.util.Scanner;
if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}
Output
18/19
19/19
Solved 2017 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/EKMvz/year-
2017
2017
Section A
Question 1
Answer
Inheritance is the mechanism by which a class acquires the properties and methods of
another class.
1. <
2. ++
3. &&
4. ? :
Answer
(c) State the number of bytes occupied by char and int data types.
Answer
Answer
1/19
(e) String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
1. System.out.println(x[1]);
2. System.out.println(x[3].length());
Answer
Question 2
Answer
1. import
2. Array
Answer
(c) State the data type and value of res after the following is executed:
char ch='t';
res= Character.toUpperCase(ch);
Answer
(d) Give the output of the following program segment and also mention the number
of times the loop is executed:
int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b == 0)
break;
}
System.out.println(a);
2/19
Answer
Explanation
This dry run explains the working of the loop.
a b Remarks
6 4 1st Iteration
12 4 2nd Iteration
In 2nd iteration, as a%b becomes 0 so break statement is executed and the loop exits.
Program control comes to the println statement which prints the output as current value of
a which is 12.
char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);
Answer
75 F
Explanation
The statement int m = ch; assigns the ASCII value of F (which is 70) to variable m.
Adding 5 to m makes it 75. In the println statement, the current value of m which is 75 is
printed followed by space and then value of ch which is F.
Question 3
Answer
a * Math.pow(x, 5) + b * Math.pow(x, 3) + c
Answer
3/19
x1 = ++x – x++ + --x
⇒ x1 = 6 - 6 + 6
⇒ x1 = 0 + 6
⇒ x1 = 6
Answer
A class can create objects of itself with different characteristics and common behaviour.
So, we can say that an Object represents a specific state of the class. For these reasons,
an Object is called an Instance of a Class.
int i = 1;
int d = 5;
do {
d=d*2;
System.out.println(d);
i++ ; } while ( i<=5);
Answer
int i = 1;
int d = 5;
for (i = 1; i <= 5; i++) {
d=d*2;
System.out.println(d);
}
Answer
Constructor Function
Constructor has the same Function should have a different name than class
name as class name. name.
4/19
Answer
0
Today i Holiday
Explanation
As the first T is present at index 0 in string s so s.indexOf('T') returns 0.
s.substring(0,7) extracts the characters from index 0 to index 6 of string s. So its result is
Today i. After that println statement prints Today i followed by a space and Holiday.
Answer
1. r1 has 5.83
2. r2 has 4.0
Explanation
1. Math.min(-2.83, -5.83) returns -5.83 as -5.83 is less than -2.83. (Note that these are
negative numbers). Math.abs(-5.83) returns 5.83.
2. Math.floor(16.3) returns 16.0. Math.sqrt(16.0) gives square root of 16.0 which is 4.0.
Answer
Result 1 = 26100200
Result 2 = 126
Explanation
1. As A and B are strings so String D=A+B+"200"; joins A, B and "200" storing the
string "26100200" in D.
2. Integer.parseInt() converts strings A and B into their respective numeric values.
Thus, x becomes 26 and y becomes 100.
3. As Java is case-sensitive so D and d are treated as two different variables.
5/19
4. Sum of x and y is assigned to d. Thus, d gets a value of 126.
(i) Analyze the given program segment and answer the following questions:
for(int i=3;i<=4;i++ ) {
for(int j=2;j<i;j++ ) {
System.out.print("" ); }
System.out.println("WIN" ); }
Answer
2. Output:
WIN
WIN
(j) What is the difference between the Scanner class functions next() and
nextLine()?
Answer
next() nextLine()
It reads the input only till space so it It reads the input till the end of line so it can
can read only a single word. read a full sentence including spaces.
It places the cursor in the same line It places the cursor in the next line after reading
after reading the input. the input.
Section B
Question 4
class : ElectricBill
6/19
Member methods:
void accept( ) — to accept the name of the customer and number of units consumed
void calculate( ) — to calculate the bill as per the following tariff:
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
Write a main method to create an object of the class and call the above member
methods.
Answer
7/19
import java.util.Scanner;
Output
8/19
Question 5
Write a program to accept a number and check and display whether it is a spy number or
not. (A number is spy if the sum of its digits equals the product of its digits.)
Answer
9/19
import java.util.Scanner;
sum += digit;
prod *= digit;
num /= 10;
}
if (sum == prod)
System.out.println(orgNum + " is Spy Number");
else
System.out.println(orgNum + " is not Spy Number");
}
}
Output
10/19
Question 6
Using switch statement, write a menu driven program for the following:
Answer
11/19
import java.util.Scanner;
switch (choice) {
case 1:
int sum = 0;
for (int i = 1; i <= 20; i++) {
int x = 2;
int term = (int)Math.pow(x, i);
if (i % 2 == 0)
sum -= term;
else
sum += term;
}
System.out.println("Sum=" + sum);
break;
case 2:
int term = 1;
for (int i = 1; i <= 5; i++) {
System.out.print(term + " ");
term = term * 10 + 1;
}
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
Output
12/19
Question 7
Write a program to input integer elements into an array of size 20 and perform the
following operations:
Answer
13/19
import java.util.Scanner;
sum += arr[i];
}
Output
14/19
Question 8
1. void check (String str , char ch ) — to find and print the frequency of a character in a
string.
Example:
Input:
str = "success"
ch = 's'
Output:
number of s present is = 3
15/19
2. void check(String s1) — to display only vowels from string s1, after converting it to
lower case.
Example:
Input:
s1 ="computer"
Output : o u e
Answer
Output
16/19
Question 9
Write a program to input forty words in an array. Arrange these words in descending order
of alphabets, using selection sort technique. Print the sorted array.
Answer
17/19
import java.util.Scanner;
System.out.println("Sorted Names");
for (int i = 0; i < n; i++) {
System.out.println(a[i]);
}
}
}
Output
18/19
19/19
Solved 2018 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/Vgz3r/year-2018
2018
Section A
Question 1
Answer
Abstraction refers to the act of representing essential features without including the
background details or explanation.
Answer
Searching Sorting
Searching means to search for a Sorting means to arrange the elements of the
term or value in an array. array in ascending or descending order.
Linear search and Binary search are Bubble sort and Selection sort are examples of
examples of search techniques. sorting techniques.
Answer
isUpperCase( ) toUpperCase( )
(d) How are private members of a class different from public members?
Answer
1/17
private members of a class can only be accessed by other member methods of the same
class whereas public members of a class can be accessed by methods of other classes
as well.
1. char
2. arrays
3. int
4. classes
Answer
1. Primitive
2. Non-Primitive
3. Primitive
4. Non-Primitive
Question 2
Answer
Value of res is 65 which is the ASCII code of A. As res is an int variable and we are trying
to assign it the character A so through implicit type conversion the ASCII code of A is
assigned to res.
Answer
java.lang
Answer
while do-while
Choose the correct option for the output of the above statements
2/17
1. BEST OF LUCK
2. BEST
OF LUCK
Answer
(d) Write the prototype of a function check which takes an integer as an argument
and returns a character.
Answer
char check(int a)
1. endsWith()
2. log()
Answer
1. boolean
2. double
Question 3
a+b3x+x2
Answer
Math.sqrt(3 * x + x * x) / (a + b)
(b) What is the value of y after evaluating the expression given below?
Answer
3/17
1. Math.floor (-4.7)
2. Math.ceil(3.4) + Math.pow(2, 3)
Answer
1. -5.0
2. 12.0
Answer
System.out.println("Incredible"+"\n"+"world");
Answer
Incredible
world
\n is the escape sequence for newline so Incredible and world are printed on two different
lines.
if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");
Answer
4/17
switch (var) {
case 1:
System.out.println("good");
break;
case 2:
System.out.println("better");
break;
case 3:
System.out.println("best");
break;
default:
System.out.println("invalid");
}
1. "ACHIEVEMENT".replace('E', 'A')
2. "DEDICATE".compareTo("DEVOTE")
Answer
1. ACHIAVAMANT
2. -18
Explanation
1. "ACHIEVEMENT".replace('E', 'A') will replace all the E's in ACHIEVEMENT with A's.
2. The first letters that are different in DEDICATE and DEVOTE are D and V
respectively. So the output will be:
ASCII code of D - ASCII code of V
⇒ 68 - 86
⇒ -18
(h) Consider the following String array and give the output
Answer
false
JAI
Explanation
1. arr[0] is DELHI and arr[3] is LUCKNOW. Length of DELHI is 5 and LUCKNOW is 7.
As 5 > 7 is false so the output is false.
5/17
2. arr[4] is JAIPUR. arr[4].substring(0,3) extracts the characters from index 0 till index
2 of JAIPUR so JAI is the output.
Answer
(j) Give the output of the following program segment and also mention how many
times the loop is executed:
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );
Answer
20
Explanation
In the loop, i is initialized to 5 but the condition of the loop is i > 10. As 5 is less than 10 so
the condition of the loop is false and it is not executed. There are no curly braces after the
loop which means that the statement System.out.println( i ); is inside the loop and
the statement System.out.println( i * 4 ); is outside the loop. Loop is not executed
so System.out.println( i ); is not executed but System.out.println( i * 4 );
being outside the loop is executed and prints the output as 20 (i * 4 ⇒ 5 * 4 ⇒ 20).
Section B
Question 4
6/17
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected (extra amount to be
added in the amount as follows)
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
void display() — To display all details of a customer such as name, coach, total amount
and mobile number.
Write a main method to create an object of the class and call the above member
methods.
Answer
7/17
import java.util.Scanner;
Output
8/17
Question 5
Write a program to input a number and check and print whether it is a Pronic number or
not. (Pronic number is the number which is the product of two consecutive integers)
Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7
Answer
9/17
import java.util.Scanner;
if (isPronic)
System.out.println(num + " is a pronic number");
else
System.out.println(num + " is not a pronic number");
}
}
Output
Question 6
10/17
Write a program in Java to accept a string in lower case and change the first letter of
every word to upper case. Display the new string.
Answer
import java.util.Scanner;
System.out.println(word);
}
}
Output
Question 7
11/17
Design a class to overload a function volume() as follows:
1. double volume (double R) – with radius (R) as an argument, returns the volume of
sphere using the formula.
V = 4/3 x 22/7 x R3
Answer
Output
12/17
Question 8
Write a menu driven program to display the pattern as per user’s choice.
Pattern 1
ABCDE
ABCD
ABC
AB
A
Pattern 2
B
LL
UUU
EEEE
Answer
13/17
import java.util.Scanner;
case 2:
String word = "BLUE";
int len = word.length();
for(int i = 0; i < len; i++) {
for(int j = 0; j <= i; j++) {
System.out.print(word.charAt(i));
}
System.out.println();
}
break;
default:
System.out.println("Incorrect choice");
break;
}
}
}
Output
14/17
Question 9
Write a program to accept name and total marks of N number of students in two single
subscript array name[] and totalmarks[].
15/17
1. The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
2. Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
Answer
import java.util.Scanner;
Output
16/17
17/17
Solved 2019 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/6dNmB/year-
2019
2019
Section A
Question 1
Answer
1. Encapsulation
2. Inheritance
Answer
unary operators operate on a single operand whereas binary operators operate on two
operands.
Answer
1. void
2. static
(d) Write the memory capacity (storage size) of short and float data type in bytes.
Answer
1. short — 2 bytes
2. float — 4 bytes
1. public
1/17
2. 'a'
3. ==
4. { }
Answer
1. Keyword
2. Literal
3. Operator
4. Separator
Question 2
Answer
if else if switch-case
if else if can test for any Boolean expression switch-case can only test if the
like less than, greater than, equal to, not equal expression is equal to any of its case
to, etc. constants.
if else if can use different expression involving switch-case statement tests the same
unrelated variables in its different condition expression against a set of constant
expressions. values.
Answer
2019
Explanation
Both Integer.parseInt() and Integer.valueOf() methods convert a string into integer.
Integer.parseInt() returns an int value that gets assigned to a. Integer.valueOf() returns an
Integer object (i.e. the wrapper class of int). Due to auto-boxing, Integer object is
converted to int and gets assigned to b. So a becomes 20 and b becomes 19. 2019 is
printed as the output.
Answer
2/17
There are 3 types of errors in Java:
1. Syntax Error
2. Runtime Error
3. Logical Error
(d) State the data type and value of res after the following is executed:
char ch = '9';
res= Character.isDigit(ch);
Answer
Data type of res is boolean as return type of method Character.isDigit() is boolean. Its
value is true as '9' is a digit.
(e) What is the difference between the linear search and the binary search
technique?
Answer
Linear search works on sorted and Binary search works on only sorted arrays.
unsorted arrays.
Question 3
Answer
Math.abs(x * x + 2 * x * y)
1. startsWith()
2. random()
Answer
1. boolean
2. double
3/17
(c) If the value of basic=1500, what will be the value of tax after the following
statement is executed?
Answer
Value of tax will be 200. As basic is 1500, the condition of ternary operator — basic >
1200 is true. 200 is returned as the result of ternary operator and it gets assigned to tax.
(d) Give the output of following code and mention how many times the loop will
execute?
int i;
for( i=5; i>=1; i--)
{
if(i%2 == 1)
continue;
System.out.print(i+" ");
}
Answer
4 2
Loop executes 5 times. The below table shows the dry run of the loop:
i Output Remark
0 42 As condition of loop (i >= 1) becomes false so loops exits and 6th iteration
does not happen.
Answer
4/17
In call by value, actual parameters are copied to formal parameters. Any changes to
formal parameters are not reflected onto the actual parameters. In call by reference,
formal parameters refer to actual parameters. The changes to formal parameters are
reflected onto the actual parameters.
Answer
Answer
phoenixland
ISLAND
Explanation
s1.substring(0) results in phoenix. s2.substring(2) results in land. concat method joins
both of them resulting in phoenixland. s2.toUpperCase() converts island to uppercase.
(h) Evaluate the following expression if the value of x=2, y=3 and z=1.
Answer
v = x + --z + y++ + y
⇒v=2+0+3+4
⇒v=9
(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};
1. System.out.println(x[3]);
2. System.out.println(x.length);
Answer
5/17
1. Big data
2. 4
Answer
A package is a named collection of Java classes that are grouped on the basis of their
functionality. For example, java.util.
Section B
Question 4
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on
following criteria
void display() — To display customer name, mobile number, amount to be paid after
discount.
Write a main method to create an object of the class and call the above member
methods.
Answer
6/17
import java.util.Scanner;
public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
7/17
}
}
Output
Question 5
Using the switch-case statement, write a menu driven program to do the following:
Letters Unicode
A 65
B 66
. .
. .
. .
Z 90
1
12
123
1234
12345
8/17
Answer
import java.util.Scanner;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j + " ");
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
Output
9/17
10/17
Question 6
Write a program to input 15 integer elements in an array and sort them in ascending order
using the bubble sort technique.
Answer
11/17
import java.util.Scanner;
//Bubble Sort
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
System.out.println("Sorted Array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output
12/17
Question 7
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + .......... xn terms
(c) void series () – To display the sum of the series given below:
Answer
13/17
public class KboatOverloadSeries
{
void series(int x, int n) {
long sum = 0;
for (int i = 1; i <= n; i++) {
sum += Math.pow(x, i);
}
System.out.println("Sum = " + sum);
}
void series(int p) {
for (int i = 1; i <= p; i++) {
int term = (int)(Math.pow(i, 3) - 1);
System.out.print(term + " ");
}
System.out.println();
}
void series() {
double sum = 0.0;
for (int i = 2; i <= 10; i++) {
sum += 1.0 / i;
}
System.out.println("Sum = " + sum);
}
}
Output
14/17
Question 8
Write a program to input a sentence and convert it into uppercase and count and display
the total number of words starting with a letter 'A'.
Example:
Answer
15/17
import java.util.Scanner;
Output
Question 9
A tech number has even number of digits. If the number is split in two equal halves, then
the square of sum of these halves is equal to the number itself. Write a program to
generate and print all four digits tech numbers.
Example:
Answer
16/17
public class TechNumbers
{
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) {
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf;
if (i == sum * sum)
System.out.println(i);
}
}
}
Output
17/17