Computer Application - Answer Key
Computer Application - Answer Key
a. Polymorphism b. Encapsulation
c. Inheritance d. Abstraction
iv. When the object of a wrapper class is assigned to primitive type variable,
the object is automatically converted to the primitive type is called as
v. How many bytes are allocated for the array a[] if int a [] = new int [4];
a. 40 bytes b. 16 bytes c. 20 bytes d. 32 bytes
System.out.println(10/0);
a. 6 b. 7 c. 9 d. 8
xii. ___________ compiles the Java source code into byte code
xiii. The java statement to access the 5th character in the string str is:
a. str.indexOf(i) b. str.charAt(4)
c.str.substring(5) d. str.length()
xiv. A method prototype which has function name display() which takes two
characters as input and an integer number as a return type is
xv. The method compareTo() returns __________ when two strings are equal
and in lowercase :
a. true b. 0 c. 1 d. false
a. Output is 15 b. 16 35 c. Output is 15
45
d. 45 15
xix. Read the following text and choose the correct answer
Question 2
3
i. Write the java expression for √(𝑎 + 𝑏)2 [2]
Ans: Math.cbrt(Math.pow(a+b),2)
iii. The following code segment should add the fifth and eight elements of the
array and display the answer as 56. However the code has errors. Fix the
code so that it compiles and runs correctly. [2]
int s[]={2,22,3,32,4,42,5,52};
if(s[3]%2==0)
int sum=s[5]+s[7];
System.out.println(sum);
Ans: sum should be initialized before the if condition and the value s[5]
should be changed to s[4]
iv. John executes the following line of the program and the answer displayed
will be a floating-point value, but he expects to get the answer as 0. Name
the error and how can the given statement be modified.
System.out.println(Math.sqrt(2)/10); [2]
v. How many times will the loop be executed? What will be the output? [2]
int a=12010;int d;
while(a>0)
{
KARNATAKA ICSE SCHOOLS ASSOCIATION
ICSE STD. X Preparatory Examination 2024
Subject: Computer Applications
d=a%100;
if(++d/3==0)
break;
else
a=a/1000;
System.out.println(d);
}
Ans: 11
13
The loop will be executed twice
vi. What will be the output of the following string methods? [2]
a. System.out.println("All the Best".length()/2);
Ans: 6
b. System.out.println("Acquatic".equalsIgnoreCase("ACQUATIC"));
Ans: true
SECTION B
KARNATAKA ICSE SCHOOLS ASSOCIATION
ICSE STD. X Preparatory Examination 2024
Subject: Computer Applications
Question 3 [15]
Design a class named Bill, which will contain the following members:
Data Members:
units,amt of int data type.
Member Functions:
Parameterised constructor to initialise units.
void show( ) to display the contents of units and amt.
void compute(int u ) :calculate the electricity bill with the help of the below
mentioned charges:
• 1 to 100 units – Rs.10/unit
• 100 to 200 units – Rs.15/unit
• 200 to 300 units – Rs.20/unit
• above 300 units – Rs.25/unit
In the main( ) create an object and initialise u with any value and calculate
amt by invoking the compute( ) function and display the contents of U an
amt using show( ) function.
Question 4 [15]
Write a program to input height of 10 Students in feet ( like 5.8, 6.1, …..) in
a single dimensional array. Sort the heights in ascending order, using
bubble sort technique and display the sorted array.
Question 5 [15]
Write a program to accept a string and convert it into uppercase. Replace all
the vowels in the string with the character ‘#’ and display the new string.
Question 6 [15]
Write a program to overload the function display() for the following tasks:
i) To display the following pattern using the function void pattern (char ch,int
n) where n is the number of lines and ch is the character to be printed.
*****
****
***
**
*
ii) To display the sum of the following series
S=𝑎2 + 𝑎4 + 𝑎6 + ⋯ … . . +𝑛 𝑡𝑒𝑟𝑚𝑠
Declaring the methods 2 marks(Should include the parameters properly, if not
no marks allotted)
First method
For loops – 4 marks(2 marks each)
Print statements- 2 marks (1 mark for each statement)
Second method
Accepting a and n from the user – 1 mark
Initializing sum = 1 mark
KARNATAKA ICSE SCHOOLS ASSOCIATION
ICSE STD. X Preparatory Examination 2024
Subject: Computer Applications
Question 7 [15]
Write a program to accept a number and check if it’s a Peterson number or
not.
A number is said to be Peterson if the sum of factorials of each digit is
equal to the sum of the number itself.
For example:
Input: Enter a number=145
Output=1!+4!+5!=145
Question 8 [15]
Define a class to accept values into a 3×3 array and find the sum of all the
odd numbers in the array.
Example:
Input: A[][]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}};