ICSE Computer Applications Previous Year Question Paper 2019 Solved For Class 10
ICSE Computer Applications Previous Year Question Paper 2019 Solved For Class 10
(ii) Which statement will be executed depend upon (ii) Which statement will be executed is decided b
the output of the expression inside if statement. user.
(b) 2019
(c) Syntax error, Runtime error, Logical error
(d) boolean
True
(e)
(ii) Linear search begins at the start of an array i.e. (ii) This technique divides the array in two halves
at 0th position. and the desired data item is searched in the halv
Question 3.
(a) Write a Java expression for the following : [2]
|x2+2xy|
(b) Write the return data type of the following functions : [2]
(i) startsWith( )
(ii) random( )
(r) If the value of basic=1500, what will be the value of tax after the following statement
is executed? [2]
tax = basic > 1200 ? 200 : 100;
id) Give the output of following code and mention how many times the loop will
execute ? [2]
int i;
for(i=5; i> =l;i~)
{
if(i%2 ==1)
continue;
System.out.print(i+ ”
}
(e) State a difference between call by value and call by reference. [2]
(f) Give the output of the following: [2]
Math.sqrt(Math.max(9, 16))
(g) Write the output for the following: [2]
String s1 = “phoenix”; String s2 =”
island”;
System.out.prindn (s1.substring(0).concat (s2.substring(2)));
System.out.println(s2.toUpperCase( ));
(h) Evaluate the following expression if the value ofx=2,y=3 and z=1. [2]
v=x+–z+y+ + +y
(i) String x[ ] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”}; [2]
Give the output of the following statements:
(i) System.out.prindn(x[3]);
(ii) System.out.prindn(x.length);
(j) What is meant by a package? Give an example. [2]
Solution................................................
(a) Math.abs((x * x) + (2 * x * y);
(b) (i) boolean
(ii) double
(c) 200
(d) 4 2
Loop will execute 5 times.
(e)
(i) In call by value the method creates its new set of (i) In call by reference, reference of the actual
variables (formal parameters) to copy the value of parameters is passed on to the method. No new
actual parameters and works with them. of variables is created.
(ii) Any change made in the formal parameter is not (ii) Any change made in the formal parameter is
reflected in the actual parameter. always reflected in the actual parameters.
(f) 4.0
(g) phoenix land
ISLAND
(h) = 2 + 0 + 3 + 4
(i) (i) Big data
(ii) 4
(j) A package is an organized collection of classes which is included in the program as
per the requirement of the program. For example java.io package is included for input
and output operations in a program. Question 1.
(a) Name any two basic principles of Object-oriented Programming.
(b) Write a difference between unary and binary operator.
(c) Name the keyword which :
(i) indicates that a method has no return type.
(ii) makes the variable as a class variable.
(d) Write the memory capacity (storage size) of short and float data type in bytes.
(e) Identify and name the following tokens :
(i) public
(ii) ‘a’
(iii) ==
(iv) {}
Solution................................................
(a) Abstraction and encapsulation are the basic principles of Object-oriented
Programming.
(b)
(i) The operators which act upon a single operand (i) The operators which require two operands for
are called unary operators. their action are called binary operators.
(c)
(i) void
(ii) static
Question 2.
(a) Differentiate between if else if and switch-case statements. [2]
(b) Give the output of the following code : [2]
String P = “20”, Q = “19”,
int a = Integer .parselnt(P);
int b = Integer. valueOf(Q);
System.out.println(a+””+b);
(c) What are the various types of errors in Java ? [2]
(d) State the data type and value of res after the following is executed : [2]
char ch = ‘9’;
res = Character. isDigit(ch) ;
(e) What is the difference between the linear search and the binary search technique?
[2]
Solution................................................
(a)
if else if switch-case
Question 4.
Design a class name ShowRoom with the following description :
Instance variables/ Data members :
String name – To store the name of the customer
long mobno – To store the mobile number of the customer
double cost – To store the cost of the items purchased
double dis – To store the discount amount
double amount – To store the amount to be paid after discount
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.
Solution................................................
import java.io.*;
import java.util.*;
class ShowRoom {
String name;
long mobno;
double cost;
double dis;
double amount;
ShowRoom( ) {
name = ” “;
mobno =0;
cost = 0;
dis = 0;
amount = 0;
}
void input( ) {
Scanner sc = new Scanner(System.in);
System.out.println(“EnterName:”);
name = sc.nextLine( );
System.out.println(“Enter Mobile number:”);
mobno = sc.nextLong( );
System.out.println(“Enter cost:”);
cost = sc.nextDouble( );
}
void calculate( ) {
if (cost <= 10000){
dis cost*5/100;
amount = cost – dis;
}
else
if (cost > 10000 && cost < = 20000){
dis = cost* 10/100;
amount cost – dis;
}
else
if (cost > 20000 && cost < = 35000){
dis = cost* 15/100;
amount = cost – dis;
}
else
if (cost > 35000){
dis = cost*20/100;
amount = cost – dis;
}
}
void display( ) {
System.out.println(“Name::” +name);
System.out.println(“Mobile No.::” +mobno);
System.out.println(“Amount::” +amount);
}
public static void main(String args( )) {
ShowRoom ob = new ShowRoom( );
ob.input( );
ob.calculate( );
ob.display( );
}
}
Question 5.
Using the switch-case statement, write a menu driven program to do the following : [15]
(a) To generate and print Letters from A to Z and their Unicode Letters Unicode
Solution................................................
import java.io.*;
import java.util.*;
class SwitchCase {
public static void main(String args[ ]) {
Scanner sc = new Scanner (System.in);
System.out.println(” 1. Enter 1 for Unicode:”);
System.out.prindn(” 2. Enter 2 for Pattern:”);
System.out.println(“Enter your choice:”);
int choice sc.nextlntO;
switch(choice){
case 1:
char ch;
System.out.println( “Letters \t Unicode”);
for (ch = ‘A’; ch < = ‘Z’; ch+ +) {
System.out.println(ch +”\t” + (int)ch);
}
break;
case 2:
int i, j;
for (i = 1; i < = 5; i+ +) {
for (j = 1; j < = i; j + +)
{
System.out.print(j + “”);.
}
System.out.printlnO;
}
break;
default:
System.out.println(“Wrong choice entered:”);
}
}
}
Question 6.
Write a program to input 15 integer elements in an array and sort them in ascending
order using the bubble sort technique. [15]
Solution................................................
import java.io.*;
import java.util’*;
class AscendingOrder {
public static void main(String args[]) {
int i, j, temp;
Scanner sc = new Scanner(System.in);
int arr[] = new int[15];
System.out.println(“Enter 15 integers:”);
for (i = 0; i < = 15; i+ +) {
arr[i] = sc.nextlntO;
for(i = 0; i < 14; i++){
for(j = 0; j < 14 -i; j + +){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr [j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println(“Elements in ascending order are::”);
for (i = 0; i < 15; i+ +) {
System.out.println(arr[i]);
}
}
}
}
Question 7.
Design a class to overload a function series() as follows: [15]
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ……………. xn terms
(b) void series (int p) – To display the following series:
0, 7, 26, 63 p terms.
(c) void series () – To display the sum of the series given below:
Solution................................................
import java.io.*;
import java.util.*;
class OverloadSeries {
void series( int x, int n) {
int i; .
double a;
double sum = 0;
for (i = 1; i < = n; i++) {
a = Math.pow(x, i);
sum = sum + a;
}
System.out.prindn(“Sum::” +sum)r
}
void series(int p) {
int i;
for (i = 1; i < = p; i++) {
System.out.prindn((i * i * i) – 1 + ” “);
}
}
void series() {
double i;
double s = 0;
for (i =-2; i < = 10; i+ +) {
s = s + 1/i;
}
System.out.println(“Sum:” +s);
}
}
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’. [15]
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING.
Sample Output : Total number of words starting with letter A’ = 4.
Solution................................................
import java.io.*;
import java.util.*;
class UpperCount {
public static void main(String args[ ]) {
int i, a;
Scanner sc = new Scanner(System.in);
String str, str1, str2;
System.out.prindn(“Enter sentence::”);
str = sc.nextLine();
strl = str.toUpperCaseO; ‘
str2 = “” + strl;
a = 0; ,
for (i = 0; i < = str2.1ength(); i+ +) {
if(str2.charAt(i) == ‘ ‘)
if(str2.charAt(i + 1) == ‘A’);
a+ +;
}
System.out.println(“Total number of words starting with letter ‘A’::” +a);
}
}
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 digit tech numbers. [15]
Example :
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.
Solution................................................
import java.io.*;
import java.util.*;
class TechNumber {
public static void main(String args[ ]) {
int i, a, b, sum;
String n;
System.out.println(“Four Digits Tech Numbers are::”);
for(i = 1000; i < 1000; i+ +) {
n = i +””;
a = lnteger,parselnt(n.substring(0, 2));
b = Integer.parselnt(n.substring(2));
sum = (int)Math.pow((a + b), 2);
if (sum == i)
System.out.println(i);
}
}
}
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 term or value in Sorting means to arrange the elements of the array in
an array. ascending or descending order.
Linear search and Binary search are examples of Bubble sort and Selection sort are examples of sorting
search techniques. techniques.
Answer
isUpperCase( ) toUpperCase( )
isUpperCase( ) function checks if a given character is in toUpperCase( ) function converts a given character to
uppercase or not. uppercase.
(d) How are private members of a class different from public members?
Answer
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
1. BEST OF LUCK
2. BEST
OF LUCK
Answer
Option 1 — BEST OF LUCK is the correct option.
System.out.print does not print a newline at the end of its output so the println statement begins
printing on the same line. So the output is BEST OF LUCK printed on a single line.
(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
3�+�2�+�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
⇒ y = 8 + (9 + 9 + 7)
⇒ y = 8 + 25
⇒ y = 33
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
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");
}
(g) Give the output of the following string functions:
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:
⇒ 68 - 86
ASCII code of D - ASCII code of V
⇒ -18
(h) Consider the following String array and give the output
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.
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.
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );
Answer
20
Loop executes 0 times.
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
Section B
Question 4
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
Type of Coaches Amount
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
import java.util.Scanner;
Output
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
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
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
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
2. double volume (double H, double R) – with height(H) and radius(R) as the arguments,
returns the volume of a cylinder using the formula.
V = 22/7 x R2 x H
3. double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H)
as the arguments, returns the volume of a cuboid using the formula.
V=LxBxH
Answer
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
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
Question 9
Write a program to accept name and total marks of N number of students in two single subscript
array name[] and totalmarks[].
Answer
import java.util.Scanner;
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. 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);
Answer
Output of the above code is 12 and loop executes 2 times.
Explanation
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
⇒ x1 = 6 - 6 + 6
x1 = ++x – x++ + --x
⇒ 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);
}
(e) Differentiate between constructor and function.
Answer
Constructor Function
Constructor is a block of code that Function is a group of statements that can be called at any point in the
initializes a newly created object. program using its name to perform a specific task.
0
Today i Holiday
Explanation
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.
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.
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
(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 can read It reads the input till the end of line so it can read a full
only a single word. sentence including spaces.
Section B
Question 4
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
import java.util.Scanner;
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
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
Question 6
Using switch statement, write a menu driven program for the following:
Answer
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
Question 7
Write a program to input integer elements into an array of size 20 and perform the following
operations:
Answer
import java.util.Scanner;
sum += arr[i];
}
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
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
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
import java.util.Scanner;
System.out.println("Sorted Names");
for (int i = 0; i < n; i++) {
System.out.println(a[i]);
}
}
}
Output
Solved 2016 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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. 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 strings are It is used to check if two variables refer to the same object
same or not 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 contents of The output of this code snippet is false as s1 and s2 point
s1 and s2 are the same. to different String objects.
(b) What are the types of casting shown by the following examples:
Answer
1. Explicit Cast.
2. Implicit Cast.
Answer
Formal parameter Actual parameter
Formal parameters appear in function definition. Actual parameters appear in function call statement.
They represent the values received by the called They represent the values passed to the called
function. 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
⇒ 66 - 68
2. ASCII Code of B - ASCII Code of D
⇒ -2
1. Math.ceil(4.2)
2. Math.abs(-4)
Answer
1. 5.0
2. 4
A Parameterised constructor receives parameters at the time of creating an object and initializes
the object with the received values.
�=�2+�2+�2T=A2+B2+C2
Answer
if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
Answer
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:
Output
5
10
Loop executes 3 times.
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
Answer
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39
1. isLetterOrDigit(char)
2. replace(char, char)
Answer
1. boolean
2. String
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
import java.util.Scanner;
public BookFair() {
bname = "";
price = 0.0;
}
price -= disc;
}
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
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
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 java.util.Scanner;
if (isPalin) {
System.out.println("Palindrome");
}
else {
System.out.println("Special");
}
}
else {
System.out.println("Neither Special nor
Palindrome");
}
}
}
Output
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:
void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
System.out.println("Sum=" + sum);
}
}
Output
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 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
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
import java.util.Scanner;
if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}
Output
Solved 2015 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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
Answer
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:
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:
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
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
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
x ch Output Remarks
97 a a 1st Iteration
98 b ab 2nd Iteration
100 d abcd 4th Iteration — As x%10 becomes true, break statement is executed and exists the loop.
�2+�22��2aba2+b2
Answer
(a * a + b * b) / (2 * a * b)
Answer
⇒ z = (11 * 16)
⇒ z = 176
Section B
Question 4
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
Question 5
Write two separate programs to generate the following patterns using iteration (loop) statements:
(a)
*
* #
* # *
* # * #
* # * # *
(b)
54321
5432
543
54
5
Answer
Output
Output
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
Average Marks Remark
40 — 59 Pass
Answer
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
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"
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
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]);
}
}
}
Output
Question 9
(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
Solved 2014 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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
2. char
(d) State one difference between the floating point literals float and double.
Answer
(e) Find the errors in the given program segment and re-write the statements correctly to
assign values to an integer array.
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
++
%
>=
&&
(b) Identify the statements listed below as assignment, increment, method invocation or
object creation statements.
1. System.out.println("Java");
2. costPrice = 457.50;
3. Car hybrid = new Car();
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 expression is equal to if-else can test for any boolean expression like less than, greater
any of its case constants than, equal to, not equal to, 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");
(e) What is constructor? When is it invoked?
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;
Answer
The composite data types are:
arr[i]=10;
obj.display();
String str;
grinds
WHEAT
Explanation:
1. str1.substring(0,2) returns "gr". str2.substring(1) returns "inds". Due to concat both are
joined together to give the output as "grinds".
2. str1.substring(2) returns "eat". It is converted to uppercase and joined to "WH" to give the
output as "WHEAT".
(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
String grade;
if (marks >= 90)
grade = "A";
else if (marks >= 80)
grade = "B";
else
grade = "C";
(e) Give the output of the following method:
Output
6
4
Explanation
⇒ a = a - ((a--) - (--a))
2. 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
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)
x=1001
y=1001.0
(ii) The output of the code is:
Question 4
Member
Purpose
Methods
movieMagic() Default constructor to initialize numeric data members to 0 and String data member to "".
To display the title of the movie and a message based on the rating as per the table given
void display()
below
Ratings Table
Write a main method to create an object of the class and call the above member methods.
Answer
import java.util.Scanner;
public movieMagic() {
year = 0;
title = "";
rating = 0.0f;
}
System.out.println(title);
System.out.println(message);
}
Output
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
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
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
import java.util.Scanner;
System.out.println("Extension:\t" +
filepath.substring(dotIdx + 1));
}
}
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
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
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
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
import java.util.Scanner;
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
Output
Solved 2013 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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
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
Answer
1. void
2. this
Answer
An exception is an abnormal condition that arises in a code sequence at run time. Exceptions
indicate to a calling method that an abnormal condition has occurred.
Question 3
Answer
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:
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
��+12��2ut+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(7, 3);
x = Math.pow(n[4], n[2]);
⇒ x = 343.0;
⇒ y = Math.sqrt(9 + 16);
y = Math.sqrt(n[5] + n[7]);
⇒ 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.)
FruitJuice() constructor to initialize integer data members to 0 and string data members to ""
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
import java.util.Scanner;
public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}
Output
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
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
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
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
Question 7
Write a program to input 10 integer elements in an array and sort them in descending order using
bubble sort technique.
Answer
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
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
Question 9
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
import java.util.Scanner;
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
Solved 2012 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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
Values of actual parameters are copied to formal Reference of actual parameters is passed to formal
parameters. parameters.
Changes made to formal parameters are not reflected Changes made to formal parameters are reflected back
back to actual parameters. to actual parameters.
2��+�22as+u2
Answer
Math.sqrt(2 * a * s + u * u)
(e) Name the type of error (syntax, runtime or logical error) in each case given below:
1. Division by a variable that contains a value of zero.
2. Multiplication operator used when the operation should be division.
3. Missing semicolon.
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;
}
}
(b) Complete the code below to create an object of Scanner class:
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:
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?
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.
(b) State the values of n and ch.
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.
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
Output
2.0
3.0
Explanation
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.
Answer
1. Float.parseFloat()
2. Character.isUpperCase()
(g) State the data type and values of a and b after the following segment is executed:
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
(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++;
}
(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
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:
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
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. 5,00,000. (TI - 1,60,000) x 10%
Is greater than Rs. 5,00,000 and less than or equal to Rs. 8,00,000 [(TI - 5,00,000) x 20%] + 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
import java.util.Scanner;
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
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
Question 8
Answer
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
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
import java.util.Scanner;
int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}
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 entry. Only It checks the condition after executing its body. If the condition
if the condition is true, the program control is true, loop will perform the next iteration otherwise program
enters the body of the loop. control will move out of the loop.
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 value of 2 Example: int b = 5 % 2; Here b will get the value of 1
which is the quotient of this division operation which is the remainder of this 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
ComputerApplications
true
Explanation
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
The loop executes 6 times
Explanation
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 = 5 + (5 - 10 + 6)
k += k++ - ++j + k
⇒k=5+1
⇒k=6
++j increments j to 10
(ii)
Output
16.0
Explanation
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
�=5�3+2��+�z=x+y5x3+2y
Answer
z = (5 * x * x * x + 2 * y) / (x + y)
Answer
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
Days Charge
Output:
import java.util.Scanner;
Output
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
import java.util.Scanner;
double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}
Question 6
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
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
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
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
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();
Output
Question 9
Write a menu driven program to perform the following tasks by using Switch case statement:
Answer
import java.util.Scanner;
public class KboatSeriesMenu
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 to print series");
System.out.println("0, 3, 8, 15, 24,....to n terms");
System.out.println();
System.out.println("Type 2 to find sum of series");
System.out.println("(1/2) + (3/4) + (5/6) + (7/8) +....
+ (19/20)");
System.out.println();
System.out.print("Enter your choice: ");
int choice = in.nextInt();
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
Solved 2010 Question Paper ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications Solved
Question Papers
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.
(b) What do you understand by type conversion? How is implicit conversion different from
explicit conversion?
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);
(c) Name two jump statements and their use.
Answer
break statement, it is used to jump out of a switch statement or a loop. continue statement, it is
used to skip the current iteration of the loop and start the next iteration.
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
1. Methods help to manage the complexity of the program by dividing a bigger complex task
into smaller, easily understood tasks.
2. Methods help with code reusability.
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=5*2+3*5
x = x++ * 2 + 3 * --x
⇒ x = 10 + 15
⇒ x = 25
Answer
They are declared using keyword 'static'. They are declared without using keyword 'static'.
All objects of a class share the same copy of Static Each object of the class gets its own copy of Non-Static data
data members. members.
They can be accessed using the class name or object. They can be accessed only through an object of the class.
Static Data Members Non-Static Data Members
Answer
length length()
length is an attribute i.e. a data member of array. length() is a member method of String class.
It gives the length of an array i.e. the number of elements stored It gives the number of characters present in a
in an array. 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
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.
(b)(ii) What will be the output of the following code?
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
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.
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);
}
}
}
Output
Question 5
Member methods:
Write a main method to create an object of a class and call the above member methods.
Answer
import java.util.Scanner;
public Student() {
name = "";
age = 0;
m1 = 0;
m2 = 0;
m3 = 0;
maximum = 0;
average = 0;
}
Question 6
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:
Answer
import java.util.Scanner;
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
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;
}
}
}
Output
Question 8
Write a program to store 6 elements in an array P and 4 elements in an array Q. Now, produce a
third array R, containing all the elements of array P and Q. Display the resultant array.
Input Input Output
P[ ] Q[ ] R[ ]
4 19 4
6 23 6
1 7 1
2 8 2
3 3
10 10
19
23
Answer
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++];
}
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
Character Frequency Character Frequency
L 2 S 1
M 1 T 2
N 1 U 1
Answer
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
2021 Exam
Solved Sample Paper 1
Sample Papers ICSE Class 10 Computer
Applications
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
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.
Answer
1. final
2. System.exit(0)
1. double
2. String
3. char
4. Integer
Answer
1. Primitive
2. Non-Primitive
3. Primitive
4. Non-Primitive
(e) What is an operator? What are the three main types of operators? Name them.
Answer
Question 2
Answer
The automatic conversion of primitive data type into an object of its equivalent wrapper class is
known as Autoboxing. For example, the below statement shows the conversion of an int to an
Integer.
Integer a = 20;
(b) Differentiate between length and length().
Answer
length length()
length is an attribute i.e. a data member of array. length() is a member method of String class.
It gives the length of an array i.e. the number of elements stored It gives the number of characters present in a
in an array. string.
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, a class
Employee can have 3 constructors as shown below:
Employee(long empId)
Employee(String name, double salary)
Employee(long empId, String name)
Due to constructor overloading, all the 3 constructors are valid for Employee class.
(d) What is the use of the keyword 'import' in Java programming?
Answer
import keyword is used to import built-in and user-defined packages into our Java program.
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");
Question 3
�2−4��b2−4ac
Answer
Math.sqrt(b * b - 4 * a * c)
(b) Evaluate the following if the value of x=7, y=5
x += x++ + x + ++y
Answer
⇒ x = x + (x++ + x + ++y)
x += x++ + x + ++y
⇒ x = 7 + (7 + 8 + 6)
⇒ x = 7 + 21
⇒ x = 28
Output
Earth is Beautiful
false
Explanation
s1.substring(4) will return a substring starting at index 4 of s1 till its end so its output will be "
is Beautiful". System.out.println("Earth" + s1.substring(4)) will concatenate "Earth"
and " is Beautiful" to given the output as "Earth is Beautiful".
As the last character of s1 is a small l not a capital L so s1.endsWith("L") returns false.
(d) Write the output of the following statement:
Output
Explanation
\t is the escape sequence for tab. \" is used to print quotes as part of the string.
(e) Give the output of the following program segment and mention how many times the loop
will execute:
int k;
for ( k = 5 ; k < = 20 ; k + = 7 )
if ( k% 6==0 )
continue;
System.out.println(k);
Answer
As there are no curly braces after the for loop so only the statement immediately following the
loop that is the if statement is part of the for loop. Again if has no curly braces so just
the continue statement is part of if. The statement System.out.println(k) is outside the
loop. The below table shows each iteration of for loop in detail:
k Remarks
5 1st Iteration
12 2nd Iteration
19 3rd Iteration
26 As the loop condition k<=20 becomes false, the loop stops iterating after 3 iterations.
(f) What is the data type returned by the following library methods?
1. isWhitespace()
2. compareToIgnoreCase()
Answer
1. boolean
2. int
if ( x > 5 )
if ( x > y )
System.out.println(x+y);
Answer
switch (ch) {
case 'c':
case 'C':
System.out.print("COMPUTER");
break;
case 'h':
case 'H':
System.out.print("HINDI");
break;
default:
System.out.print("PHYSICAL EDUCATION");
}
(i) Give the output of the following:
1. Math.pow(36,0.5) + Math.cbrt(125)
2. Math.ceil(4.2) + Math.floor(7.9)
Answer
1. 11.0
2. 12.0
Working
Math.pow(36,0.5) gives 6.0 and Math.cbrt(125) gives 5.0. 6.0 + 5.0 = 11.0
Math.ceil(4.2) gives 5.0 and Math.floor(7.9) gives 7.0. 5.0 + 7.0 = 12.0.
if(n1>n2)
r = true;
else
r = false;
Answer
Question 4
A private Cab service company provides service within the city at the following rates:
Member methods:
CabService() — Default constructor to initialize data members. String data members to '' ''
and double data members to 0.0.
CAR TYPE:
KILOMETER TRAVELLED:
TOTAL BILL:
Create an object of the class in the main method and invoke the member methods.
Answer
import java.util.Scanner;
public CabService() {
car_type = "";
km = 0.0;
bill = 0.0;
}
Output
Question 5
Write a program to search for an integer value input by the user in the list given below
using linear search technique. If found display "Search Successful" and print the index of
the element in the array, otherwise display "Search Unsuccessful".
{75, 86, 90, 45, 31, 50, 36, 60, 12, 47}
Answer
import java.util.Scanner;
public class KboatLinearSearch
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = {75, 86, 90, 45, 31, 50, 36, 60, 12, 47};
int l = arr.length;
int i = 0;
if (i == l) {
System.out.println("Search Unsuccessful");
}
else {
System.out.println("Search Successful");
System.out.println(n + " present at index " + i);
}
}
}
Output
Question 6
An Abundant number is a number for which the sum of its proper factors is greater than the
number itself. Write a program to input a number and check and print whether it is an
Abundant number or not.
Example:
Consider the number 12.
Answer
import java.util.Scanner;
if (sum > n)
System.out.println(n + " is an abundant number");
else
System.out.println(n + " is not an abundant
number");
}
}
Output
Question 7
(i) void Number(int num, int d) — To count and display the frequency of a digit in a number.
Example:
num = 2565685
d=5
Frequency of digit 5 = 3
(ii) void Number(int n1) — To find and display the sum of even digits of a number.
Example:
n1 = 29865
Sum of even digits = 2 + 8 + 6 = 16
Write a main method to create an object and invoke the above methods.
Answer
while (num != 0) {
int x = num % 10;
if (x == d) {
f++;
}
num /= 10;
}
while (n1 != 0) {
int x = n1 % 10;
if (x % 2 == 0) {
s = s + x;
}
n1 /= 10;
}
Output
Question 8
Write a menu driven program to perform the following operations as per user’s choice:
(i) To print the value of c=a²+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and
b=3.0 is a constant.
A
AB
ABC
ABCD
ABCDE
Answer
import java.util.Scanner;
switch (choice) {
case 1:
final double b = 3.0;
for (int a = 1; a <= 20; a += 2) {
double c = Math.pow(a, 2) + 2 * a * b;
System.out.println("Value of c when a is "
+ a + " = " + c);
}
break;
case 2:
for (char i = 'A'; i <= 'E'; i++) {
for (char j = 'A'; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
break;
default:
System.out.println("INVALID CHOICE");
}
}
}
Output
Question 9
Write a program to input integer elements into an array of size 20 and perform the following
operations:
1. Display largest number from the array.
2. Display smallest number from the array.
3. Display sum of all the elements of the array
Answer
import java.util.Scanner;
sum += arr[i];
}
Next
2021 Exam
Solved Sample Paper 2
Sample Papers ICSE Class 10 Computer
Applications
Section A
Question 1
Answer
Answer
All objects of a class share the same copy of static Each object of the class gets its own copy of instance
variables. variables.
Static Variables can be accessed using the class name Instance Variables can be accessed only through an object
or object. of the class.
(c) What are identifiers in Java? List three identifier formation rules.
Answer
Identifiers are used to name different parts of a program such as variables, methods, classes,
objects, etc. Three identifier formation rules are:
1. true
2. 'X'
3. "false"
4. 25.75
Answer
1. boolean literal
2. Character literal
3. String literal
4. Floating Point Literal
(e) Name the wrapper classes of char type and long type
Answer
Question 2
Answer
1. Logical Error
2. Syntax Error
Answer
1. switch-case statement can only test for equality whereas if-else-if can test for any Boolean
expression.
2. switch-case tests the same expression against constant values while if-else-if can use
different expression involving unrelated variables.
Answer
The break statement terminates the current loop or switch statement. The execution then
continues from the statement immediately following the current loop or switch statement.
(d) Write the prototype of a function check which takes a String and a character as an
argument and returns a boolean.
Answer
boolean check(String str, char ch)
(e) What is the use of the keyword 'this' in Java programming?
Answer
The 'this' keyword refers to the current object in a function or constructor. It is primarily used to
resolve the conflict between method parameters and instance variables/fields.
Question 3
(�−ℎ)2�+(�−�)2�a(x−h)2+b(y−k)2
Answer
Math.sqrt((Math.pow((x-h), 2) / a) + Math.pow((y-k), 2) / b)
(b) Give the output of the following:
1. Math.max(Math.ceil(14.5), 15.5)
2. Math.sqrt(Math.abs(-225))
Answer
1. 15.5
2. 15.0
Explanation
m -= 9 % ++n + ++n / 2
Answer
⇒ m = m - (9 % ++n + ++n / 2)
m -= 9 % ++n + ++n / 2
⇒ m = 10 - (9 % 7 + 8 / 2)
⇒ m = 10 - (2 + 4)
⇒ m = 10 - 6
⇒m=4
Output
a=49.0
b=5.0
Explanation
(f) Rewrite the following program segment using the corresponding while loop:
int f=1, i;
for(i=1; i<=5; i++)
f*=i;
System.out.println(f);
Answer
30
1020
Explanation
Integer.parseInt and Integer.valueOf convert the strings a and b into their corresponding numeric
integers. x + y adds 10 and 20 to give 30 as the output. a and b are strings so addition operator
concatenates them and prints 1020.
Output
x=3
false
Explanation
⇒ 80 - 77
ASCII of P - ASCII of M
⇒3
Value of x becomes 3. As x is not equal to 0 so ternary operator assigns false to ret. foo method
returns back this false that gets assigned to a in main method and then printed as the output.
Answer
Constructor has the same name as class name whereas function should have a different name
than class name.
(j) For a class Toy, create two objects "Barbie" and "Stack"?
Answer
Question 4
Member methods:
void display() — To display the employee name, salary and all salary components.
Write a main method to create object of the class and call the member methods.
Answer
import java.util.Scanner;
public class Pay
{
String name;
double salary;
double da;
double hra;
double pf;
double grossSal;
double netSal;
void calculate() {
da = salary * 15.0 / 100;
hra = salary * 10.0 / 100;
pf = salary * 12.0 / 100;
grossSal = salary + da + hra;
netSal = grossSal - pf;
}
void display() {
System.out.println("Employee Name: " + name);
System.out.println("Salary: " + salary);
System.out.println("Dearness Allowance: " + da);
System.out.println("House Rent Allowance: " + hra);
System.out.println("Provident Fund: " + pf);
System.out.println("Gross Salary: " + grossSal);
System.out.println("Net Salary: " + netSal);
}
Output
Question 5
A Dudeney number is a positive integer that is a perfect cube such that the sum of its digits
is equal to the cube root of the number. Write a program to input a number and check and
print whether it is a Dudeney number or not.
Example:
Sum of digits = 5 + 1 + 2 = 8
Cube root of 512 = 8
import java.util.Scanner;
if (s == cubeRoot) {
System.out.println(n + " is a Dudeney number");
}
else {
System.out.println(n + " is not a Dudeney
number");
}
}
else {
System.out.println(n + " is not a Dudeney number");
}
}
}
Output
Question 6
Write a menu-driven program to display the following patterns as per the user’s choice:
(a)
1234567
12345
123
1
(b)
11111
22222
33333
44444
55555
Answer
import java.util.Scanner;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
System.out.print(i);
}
System.out.println();
}
break;
default:
System.out.println("Incorrect Choice");
}
}
}
Output
Question 7
(a) void series(int a, int n) — To display the sum of the series given below:
(b) void series(int n) — To display the sum of the series given below:
Write a main method to create an object and invoke the above methods.
Answer
import java.util.Scanner;
void series(int n) {
double sum = 0;
int m = 1;
for (int i = 1; i <= n; i++) {
double t = ((double)i / (i + 1)) * m;
sum += t;
m *= -1;
}
System.out.println("Series Sum = " + sum);
}
Output
Question 8
Write a program to input 10 alphabets in an array. Now ask the user to input an alphabet
and search if the alphabet is present in the array or not using linear search technique. If
found display "Search Successful" and print the index of the alphabet in the array,
otherwise display "Search Unsuccessful".
Answer
import java.util.Scanner;
int i = 0;
for (i = 0; i < 10; i++) {
if (arr[i] == ch) {
break;
}
}
if (i == 10) {
System.out.println("Search Unsuccessful");
}
else {
System.out.println("Search Successful");
System.out.println(ch + " present at index " + i);
}
}
}
Output
Question 9
Write a program to create three single dimensional arrays cod[], pric[], qty[] to store
product code, unit price and quantity of each product for 10 products. Calculate the total
cost of each product and print the result in tabular form including product code, unit price,
quantity and total cost of each product. At the end print total of price, total of quantity and
the total of costs.
Answer
import java.util.Scanner;
public class KboatProducts
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int cod[] = new int[10];
double pric[] = new double[10];
int qty[] = new int[10];
double tp = 0;
long tq = 0;
double tc = 0;
System.out.println("Code\tPrice\tQty\tCost");
for (int i = 0; i < 10; i++) {
double cost = qty[i] * pric[i];
tp += pric[i];
tq += qty[i];
tc += cost;
System.out.println(cod[i] + "\t" + pric[i] + "\t" +
qty[i] + "\t" + cost);
}
Section A
Question 1
(a) What are the differences between Procedural Programming and Object-Oriented
Programming?
Answer
The abstraction is at procedure (function) level. The abstraction is at object (class) level.
Interaction with program is via direct function Interaction with program is via functions defined in the class
calls. only.
Real world is represented by 'procedures' Real world is represented by objects and the operations that
operating on data. can be performed on these objects.
Data and functions are separate. Data and functions are encapsulated into a single unit.
Procedural Programming Object-Oriented Programming
Data security is less as it contains lesser features It is more secure as one of its primary features include data
to protect the data. hiding.
A function can access any other function's data by Only the data whose access has been granted can be accessed
calling that function. by another function.
Limited and difficult code reusability. Versatile and easy code reusability.
Code is difficult to modify, extend and maintain. Code is easy to modify, extend and maintain.
Some examples of Procedural Programming Some examples of Object Oriented languages are C++, Java,
languages are C, COBOL, Pascal. C#.
Answer
Explanation
1. Scanner class
2. Wrapper classes
Answer
1. java.util
2. java.lang
(d) What is meant by Token? Name all the tokens which are used in Java.
Answer
A token is the smallest element of a program that is meaningful to the compiler. The different
types of tokens in Java are:
1. Identifiers
2. Literals
3. Operators
4. Separators
5. Keywords
Answer
Implicit conversions are automatically performed by Explicit conversions are performed by the programmer
the Java compiler. using the cast operator.
Example:
Example:
long a = 98453670116L;
int a = 10;
long result;
double b = 25.5;
int b = 100;
float c = (float)(a + b);
result = a + b;
Question 2
Answer
Answer
System.out.print() System.out.println()
It prints data to the console but the cursor remains at the end It prints data to the console and places the
of the data in the same line. cursor in the next line.
Next printing takes place from the same line. Next printing takes place from next line.
Answer
1. indexOf()
2. Math.floor()
Answer
The parameters that appear in the method definition are called formal or dummy parameters
whereas the parameters that appear in the method call are called actual parameters.
Answer
The purpose of new operator is to instantiate an object of the class by dynamically allocating
memory for it.
Question 3
�(�ℎ+�22)m(ah+2v2)
Answer
Math.sqrt(m * (a * h + v * v / 2))
(b) Evaluate the following if the value of x = 20 and y = 20 and z = 10
z *= ++x * (y--) - y
Answer
⇒ z = z * (++x * (y--) - y)
z *= ++x * (y--) - y
Output
p=6
q=37
Explanation
if (a == 10)
System.out.println("TEN");
else if (a == 50)
System.out.println("FIFTY");
else if (a == 100)
System.out.println("HUNDRED");
else
System.out.println("UNKNOWN");
Answer
switch (a) {
case 10:
System.out.println("TEN");
break;
case 50:
System.out.println("FIFTY");
break;
case 100:
System.out.println("HUNDRED");
break;
default:
System.out.println("UNKNOWN");
}
(e) Rewrite the following program segment using for loop:
int n = 152, s = 0;
while (n != 0) {
int d = n % 10;
s = s + d;
n = n / 10;
}
Answer
int s = 0;
for (int n = 152; n != 0; n = n / 10) {
int d = n % 10;
s = s + d;
}
(f) Rewrite the following program segment using ternary operator:
if (m == 0)
System.out.println("Hello");
else
System.out.println("Good Day");
Answer
Answer
break statement at the end of case is optional. Omitting break leads to program execution
continuing into the next case and onwards till a break statement is encountered or end of switch
is reached. This is termed as fall through. For example, consider the below program:
int x, y;
for (x = 9, y = 4; x <= 45; x+=9) {
if (x % y == 0)
break;
}
System.out.println(x);
Answer
Output
36
Loop executes 4 times
Explanation
x y Remarks
9 4 1st Iteration
18 4 2nd Iteration
27 4 3rd Iteration
x y Remarks
void strop(String s) {
char a = s.charAt(3);
int b = s.indexOf('M');
String t = s.substring(3,6);
boolean p = s.equals(t);
System.out.println(a + " " + b + " " + t + " " + p);
}
What will be the output for strop("COMPUTER")?
Answer
Output
P 2 PUT false
Explanation
1. s.charAt(3) returns the letter at index 3 of s which is P. This gets assigned to variable a.
2. Index of letter M in s is 2.
3. s.substring(3,6) returns a substring of s starting at index 3 till index 5. So PUT gets
assigned to t.
4. As PUT is not equal to the value of s (which is COMPUTER) so p becomes false.
System.out.println("nine:" + 5 + 4);
System.out.println("nine:" + (5 + 4));
Answer
Output
"nine:54"
"nine:9"
Explanation
1. First "nine:" + 5 is evaluated. As one operand of addition operator is string so implicit conversion
converts 5 to string and concatenates it with "nine:" and the result is "nine:5". Next "nine:5" + 4
is evaluated and similarly it results in "nine:54".
2. Due to brackets, first (5 + 4) is evaluated. As both operands are numeric so arithmetic addition
takes place resulting in 9. Next "nine:" + 9 is evaluated and results in "nine:9".
Section B
Question 4
char cardType — Type of card, 'P' for Platinum, 'G' for Gold, 'S' for Silver.
Member methods:
Customer(String name, long num, char type, double amt) — Parameterised constructor to
initialize all data members.
Write a main method to input the card details from the user then create object of the class
and call the member methods with the provided details.
Answer
import java.util.Scanner;
void compute() {
switch (cardType) {
case 'S':
cashback = 2.0 * purchaseAmount / 100.0;
break;
case 'G':
cashback = 5.0 * purchaseAmount / 100.0;
break;
case 'P':
cashback = 8.0 * purchaseAmount / 100.0;
break;
default:
System.out.println("INVALID CARD TYPE");
}
}
void display() {
System.out.println("Card Holder Name: " + cardName);
System.out.println("Card Number: " + cardNo);
System.out.println("Purchase Amount: " +
purchaseAmount);
System.out.println("Cashback: " + cashback);
}
Question 5
Using switch-case statement write a menu driven program for the following:
Answer
import java.util.Scanner;
case 2:
System.out.print("Enter n: ");
int n = in.nextInt();
double s = 0;
for (int i = 1; i <= n; i++) {
double f = 1;
for (int j = 1; j <= i; j++) {
f *= j;
}
double t = i / f;
s += t;
}
System.out.println("Series Sum = " + s);
break;
default:
System.out.println("Incorrect Choice");
}
}
}
Output
Question 6
Write a program to input and store roll number and total marks of 20 students. Using
Bubble Sort technique generate a merit list. Print the merit list in two columns containing
roll number and total marks in the below format:
Answer
import java.util.Scanner;
//Bubble Sort
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (marks[j] < marks[j + 1]) {
int t = marks[j];
marks[j] = marks[j+1];
marks[j+1] = t;
t = rollNum[j];
rollNum[j] = rollNum[j+1];
rollNum[j+1] = t;
}
}
}
Write a class with the name Area using function overloading that computes the area of a
parallelogram, a rhombus and a trapezium.
Formula:
Write a main method to create an object and invoke the above methods.
Answer
import java.util.Scanner;
Question 8
Write a program to print the sum of negative numbers, sum of positive even numbers and
sum of positive odd numbers from a list of numbers entered by the user. The list terminates
when the user enters a zero.
Answer
import java.util.Scanner;
if (n == 0) {
break;
}
if (n < 0) {
nSum += n;
}
else if (n % 2 == 0) {
eSum += n;
}
else {
oSum += n;
}
}
Question 9
Write a program to take a number from the user as input. Find and print the largest digit
of the number.
Example:
Answer
import java.util.Scanner;
Output