0 ratings0% found this document useful (0 votes) 190 views56 pagesClass 10 Computer Solved 4-7
FRANK Computer Solved 4-7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Model Test Paper
(Solved)
SECTION A (40 Marks)
Attempt all questions.
QUESTION 1
Choose the correct answer and write the correct option. (20)
(i) float type data occupies ____ bits.
(a) 4
(b) 32
8
(d) 64
Ans: (b) 32
INote: float size in bytes=4 bytes= 4x 8 bits=32 bits]
(ii) Statement encloses multiple lines within a pair of opening and closing curly brackets |).
(a) Sequential
(®) Iteration Statement
(©) Compound Statement
(d) Jump Statement
(c) Compound Statement
The correct if statement for the following ternary statement is:
max=(a>b)?a:b
(a) iffa>b)
‘System.out.printIn(“greater number:"+max)
(©) iffa>d)
System.out.printin(a);
else
System.out printin(®);
(©) iffa>d)
max=a;
else
max=b;
(d) ifta>b)mi
else
max=a;
Ans: (c) ifla>b)
max=a;
else
max=b;
(iv) Math.rint(6.5) results to.
(@) 6
(b) 7.0
(©) 60
@7
Ans: (c) 6.0
(Note: returns double data type value to the nearest rounded integer.)
(v) Functions having the same names but different signatures defined within the same
class is termed as.
(@) Encapsulation
(b) Funetion Overriding
(©) Function Overloading
(@) Abstraction
Ans: (c) Function Overloading
(vi) Output of the following statement:
System.out. printin(“Character.toUpperCase(T));
@ 1
@) 0
(o) true
(d) false
Ans: (c) true
(vii) int n{J=(1,2,3,5,7,9,13,16] what is the value of x:
x=Math.pow(n{2],nl1);
(@ 5
() 6
9
@ 3
Ans: (c) 9
[Note: n[2j=3 and n[1]=2 hence, #°=9]
(vili) Collection of same types of values:
(@) Class
(6) Object
(o) Array
(@) Package
Ans: (c) Array(ix)
Ans:
(x)
Ans:
(xi)
Ans:
(xii)
Ans:
(xiv)
double x=32.7;
What is the data type of x?
(@) Non Primitive
(b) Class
(0) Primitive
(d) None of the above
(©) Primitive
What is the output of the following code:
for(int a=2;a<=8;a+=2)
!
System.out print(a+2);
}
(a) 2468
() 268
(©) 46810
(d) 26810
(c) 46810
Conversion of Integer to int, Float to float, Long to long, etc. is known as:
(a) Autoboxing
() Unboxing
(c) Implicit conversion
(d) Explicit conversion
(b) Unboxing
The method to check if a character is in Uppercase or not is:
(a) isLetter(char)
(b) isAlpha(char)
(©) isUpper(char)
(@) isUpperCase(char)
(d) isUpperCase(char)
What will be the output of the following code?
System.out.printin (Integer.parselnt("20")+25.25);1
(a) 45.0
() 45.25
(co) 45
(d) 20
(b) 45.25
Given an array 5,1,7,9,2 what will be array like after one passes of Bubble sort in
ascending order?
(@) 1,5,7,9.2
() 15,729232
Ans:
(xv)
Ans:
(xvi)
Ans:
(xvii)
ICSE Computer Applic
(©) 9,1,5,7,.2
(d) 5,7,9,2,1
(b) 1,5,7,2,9
What will be the output after the following statement is executed:
String s="Six”;
System.out.print(a+b+s);
(@ 6Six
(b) 24S8ix
(c) 24
(d) None of the above
(a) 6Six
class XYZ
f
public void cale(int a, int b)
+
}
}
Identify the scope of the variable a & b.
(a) Instance variable
(®) Class Variable
(c) Argument Variable
(@) None of the above
(©) Argument Variable
What will be the output of the given code when opt=‘g’:
switch(opt)
t
case ‘1’:
System.out.println(‘Red”);
break;
case ‘g’:
System.out.println(“Green”);
case ‘b':
System.out.println(“Blue");
break;
default:
System.out.printin(“RGB Colour Model”);
(@) Green
(b) Green
BlueModel Test Papers ™
CTT o/-'
Ans:
(xviii)
(xix)
(xx)
Ans:
(c) RGB colour Model
(d) Blue
(b) Green
Blue
Instance variable can have value for each instantiated object of the class.
(a) Same
(b) Different
(c) Constant
(d) One
(b) Different
What will be the output of the following code?
‘System.out.print(“ACHIEVEMENT .replace(E, #)):
(@) ACHI#V#M#NT
(6) ACHI#VEMENT
(©) ACHIEVEMENT
(d) ACHI#V#MENT
(a) ACHI#V#M#NT
Return type by the library function compareTo() is:
(a) int
() double
(c) boolean
(d) String
(a) int
w@
Ans.
Gi)
(ii)
Ans.
Gv)
Distinguish between character and string constant. 2
Character constant represents a single character enclosed with a single quote,
e.g. ‘a’, ‘4’, ete.
String constant is a set of alphabets or alphanumerical characters enclosed
within double quotes, e.g. “New Delhi”, “15 August” ete.
Differentiate between syntax error and logical error. 2
| Syntax Error: An error in the syntax of @ coding entered by a programmer and
Which is caught by the compiler is known as syntax error.
Logieal Error: An error which oceurs due to some incorreet logic used in a program
and generates an incorrect output based on that is known as logical error.
What are the components of a class? i
Methods and class variables are the components of a class.
If, string s="Ashish Kumar"? cl
String si="Computer Teacher"?
What do the following functions return for:@
Ga)
t1n(s.indexOf (s.charAt (4)) 7
(
ati) rintIn(sl+s,substring(5))i
Go) tin (s-equals(si));
Ans. (i)
1
(ui) Computer Teacherh Kumar
(iv) false
(v) What do you mean by instance variable? (2
Ans. An instance variable is a variable defined in a class, for which each object in the
class has a separate copy.
(vi) What is the difference between x=5 and x==5? 2)
Ans. x=5. In this expression, x=5 assigns 5 to the variable x
x==5, In this expression, it is tested whether x is equal to 5 or not.
If yes, the expression has boolean value true, otherwise false.
(vii) What is a package? Give an example. 2)
‘Ans. Grouping of several class definitions together into a logical group is called a package.
e.g. java.io.
Write any two advantages of using functions in a program. (2)
Ans. (i) It reduces the complexity of the program.
(ii) It enhances reusability of code.
(ix) Differentiate between member and local variables. (2)
Ans. Member Variable Local Variable
(i) Member variables can be accessed | (i) Local variables exist only within the
throughout the program. function where they are declared.
(ii) A member variable’s lifetime is same| (ii) A local variable’s lifetime is within]
as lifetime of the program. the function.
(x) Evaluate x=++y +2y if y=6. (2
Ans. Initially, y = 6
7427
7+14=21SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of the programs in either Blued
environment or any program environment with Java as the base. Each program
should be written using Variable Description /Mnemonic Codes such that the
logic of the program is clearly depicted. Flowcharts and Algorithms are not
required.
‘An electricity board charges the bill depending on the number of units consumed as
follows: (15)
Units Consumed Rate per unit
First 100 units 40 p. per unit
Next 200 units 60 p. per unit
Above 300 units Re, 1 per unit
import java-util.*;
class Electricity
{
public static void main(String args(])
{
Scanner sc=new Scanner (System. in);
int uy
double b=0.0;
System.out.printin ("Enter the number of units consumed”);
ussc.nextint ();
if (u<=100)
b=u*0.40;
else if (u>100¢su<=300)
b=100*0. 40+ (u-100) *0.60;
else
b=100*0. 40+200*0. 60+ (u-300) *1.00;
System.out.printin ("Your Bill Amount is Rs."+b);— — --- 2+
= Computer Applications Papers
_e—ee ee epee Applicntions Peps
‘ariable Description
Verwiie Name | Data Type] Dexvipion }
- int | to accept the no. of units
. double | to store the bill amount
Write c program to display all Mersenne numbers between 1...n using the method
mame MersenneNos (int nj where n has to be in the range 1-20. 05)
‘Mersenne numbers are the ones which are one less than a power of 2, ie., 1(2'-1),
S321. 7244) Some Mersenne numbers are 1, 3, 7, 15, 31, 63, ete..]
+20");Variable Description
Variable Name | Data Type | Description
n int to accept the range value
num long to store the Mersenne number
i int to run the loop
Write a program to input a string to calculate the tota
vowels present in it and also reverse the string.
Ans. import java.util.t;
class stringProcess
(
public static void main(Str:
c
Scanner sc=new Scanner (System. in) +
String s,
char ch;
int i,1,cv=0;
System.out.printin ("Enter any string value”);
{
reve";
c.nextLine ()7
slength (7
for (i=0;iw)
usmid-1;
else if (wt{mid]=, <=,!= (Relational Operator), = (Assignment Operator]
(x) What is the output of the following code?
int x;244 ICSE Computer Applications Papers
fortx=1:x<=3;x44);
System.out.printix),
(a) 123
(b) 1234
4
1
Ans: (c) 4
(xi) Full form of JVM
(a) Java virtual mechanism
(6) Java virtual method
(©) Java virtual machine
(d) Java visual machine
Ans: (c) Java virtual machine
(xii) The ASCII code for ‘E’
(a) 101
(b) 69
() 7
(d) 99
Ans: (b) 69
(Note: A-Z: 65-90 , a-z: 97-122]
(xiii)
Ans:
(xiv)
Ans:
(xv)
Ans:
access specifiers allow accessibility of members by all classes in the same
package, but only by subclasses in a different package.
(a) private
(b) public
(©) protected
(d) default
(c) protected
‘A package contains group of ___-
(a) classes
(b) methods
(c) objects
(d) Arrays
(a) classes
____ features of Oops allows a class to use the properties and methods of another
class.
(a) Polymorphism
(b) Encapsulation
(c) Abstraction
(d) Inheritance
(d) Inberitance[Motel Test Papers ee
(xvi)
Ans:
(xvii)
Ans:
(xviii)
Ans:
(xix)
Ans:
(xx)
Ans:
QUESTION 2
Java intermediate code obtained after compilation:
(a) Byte Code
(b) Source Code
(c) Object Code
(d) Class Code
(a) Byte Code
Identify the correct assignment of the String value “BLUES”.
(a) char ch=(B,L,U,E,dI;
(6) char ch=('BYLyU, Ey};
( ‘BYL'U'B J);
@ BLUES”;
(c) char chf]=('B'L,UE)S};
class variable can have value for each instantiated object of the class.
(a) Same
(b) Different
(©) Constant
@ One
(a) Same
Invoking a function by passing the objects of a class is termed as:
(a) Call by reference
(6) Call by value
() Call by constructor
(d) None of the above
(a) Call by reference
Identify the type of conversion
double x=23.3;
int y=(indx;
(a) Implicit
(b) Explicit
() Autoboxing
(d) Unboxing
(b) Explicit
(4) Rewrite the program snippet, using the do-while loop. (2
int i,fels
)
for (
fafti7
em, out.printla(£)7
—_——246 ICSE Computer Applications Papers
Ans: int i
ntin(£);
(ii) Name the four int data types in Java (21
Ans: byte, short, int and long.
(iii) State the difference between token and identifier. [2]
Ans: Token: The smallest individual unit used in a program,
Identifier: It is the name which we use to call a particular entity of a program
and it should not be a keyword.
(iv) Name the following: (2)
(i) A package that is invoked by default.
(ii) A keyword to use the classes defined in a package.
Ans: (i)
(ii)
(v) Explain function overloading. (21
Ans: Two or more functions having the same name but different signature defined within
the same class is known as function overloading. Java identifies the methods by
comparing their signatures.
(vi) Give the output of the following code: 12)
m=100;
Ans: m is 0 :
(vii) State conditions under which binary search is applicable, 21
‘Ans: For binary search, (i) the list must be sorted, and (ii) lower bound, upper bound and
the sort order of the list must be known.
(viii) Write the statement to declare and initialise @ boolean variable. (2)
Ans: coolean »
(ix) Evaluate d, if num ia
d = numl++ + num2++ ~ num?
Ans: d=5+3-4
B-4(2)
(x) Write the following condition using ternary operator:
If amount is greater than 10000 and less than 50000, th
it is 0.
Ans: commission=(amount>10000 && amount<50000) 27000305
e commission is % 7000 else
SECTION B (60 Marks)
Attempt any four questions from this section.
‘The answers in this seetion should consist of programs in either Blues environment
or any program environment with Java as the base. Each program should be
written using Variable Descriptions /Mnemonic Codes such that the logic of the
program is clearly depicted. Flowcharts and Algorithms are not required.
Define a class to accept name and marks in Computer applications for 20 students in
.s in descending order and display the names
a two different arrays. Arrange the mark:
of first 10 students along with their marks in descending order. [Bubble Sort] (15)
Ans: import java-util.*;
class Marks
(
public static void main(String args(])
{
ew Scanner (System. in) 7
Scanner sc
double marks[]=new double [20], temp;
String name{]=new String[20], templ;
int ids
system.out.println("Enter 20 names”);
<20;i++)
for (i=!
(
c.nextLine ()
name [i] =
system.out-printin ("Enter 20 marks”);
pi<207it+)
race
name [i}=se.nextLine () 7
}
for (is07i<
‘
19;itt)248 ICSE Computer Applications Papers
ja)
if (marks (j}>marks(}+1])
J=marks [341];
marks {j+1}=temp;
templ=name[
m.out.printin("The first 10 heighest scoring marks with
their nding names are:”);
sci0;it+)
intln("Name:”+name[i]+”\tMarks:”+marks[i]);
Variable Description
Variable Name Data Type Description
marks {] double ‘An array to store marks
name [] String ‘An array to store names
temp double To store marks temporarily
templ String ‘To store name temporarily
i int To run the loop
j int To run the loop
QUESTION 4:
Using a switch statement, write a menu-driven program to convert a given temperature
from Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate
error message should be displayed.
(use the formulae C = 5/9 (F-32) and F = 18 * C + 32) 05)Public static void main(String args(J)
{
Scanner sc=new Scanner (System. in)
double t,cts
int ch;
System. out.println ("Enter Your Choice”)
system.out.printin("1.Convert Celsius to Fahrenheit”);
system.out .printin(*2.Convert Fahrenheit to Celsius”);
ch=sc-nextint ();
switch (ch)
{
case 1:
system.out .printIn ("Enter the temperature in celsius”);
tesc.nextDouble();
-8*t+32;
ct
systen.out.printin ("The temperature in Fahrenheit: "+ct+ӣ");
break;
case 2:
systen.out.printla("Enter the temperature in Fahrenheit”);
tesc.nextDouble() 7
et=5/9* (t-32)7
system.out .printin ("The temperature in Celsius:”#ctt"c");
break;
default:
system.out-printin ("Wrong choice”) +
Variable Description
Variable name Data type Description
t double to accept the temperature
ct double to store the converted temperature
ch int to accept the choice
any number from the user and check and display whether it
not a Boring Number. eemedans rua
number is called boring if all of the digits at even
Define a class to input
is a Boring Number or
[Boring Number: A positive250 ICSE Computer Applications Papers
positions in the number are even and all of the digits at odd positions are odd.
For example, the number
Input: 1478
Output: 1478 is boring number.
[As the odd positions include the digits (1, 7/ which are odd and even positions include
the digits (4, 8) which are even.]
Ans: import java.util.*;
Boring
clas
public static void main(String args[])
Scanner sc=new Scanner (System.in);
int n,c=0,d, temp, f=1;
System.out.println("Enter any number”);
n=sc.nextint ();
temp=n;
while (temp!=0)
{
d=temps10;
ct:
temp/=10;
i
temp=n;
wh,
{
2 (temp!=0)
d=temp$10;
if ((c82:
{
LL (ct
1 66 a82
eads:
£=0;
break;
if (t
system.out-printIn("It is boring number”) ;
e
System.out.printin(*It is not a boring number”);Model Test Papers
—_— nnn
Variable Description
Variable Name Data Type Description
a int To store a number
int To count digits in number
ad int ‘To store digit from the number
temp int To store the number temporarily
f int To store program logic flow control
(1-true,2-false]
QUESTION 6——$
A salesman is paid commission on the following basis:
Write a program
Sales Commission Rate
Up to & 10,000 2%
% 10,001 to % 20,000 3%
% 20,001 to % 50,000 5%
% 50,001 to & 70,000 8%
Above 70,000 10%
amount, commission rate and commission.
Ans: import java-util.*;
class
(
salesMan
public static void main(String args[])
{
Scanner sc=new Scanner (System. in);
double samt, comm=0.0,r=0.07
system.out.printin ("Enter Your Sale
samt=sc.nextDouble ()
if (samt<=10000)
fl
r=0.027
comm=samt*r7
,
else if(sam
(
¢>=10001 && samt<=20000)
r=0.037
comm=samt*ri
)
else if(samt>=20002 6& samt<=50000)
to accept the sales amount and calculate the commission. Print sales
15)
Amount”) ;r=0.05;
comm=samt*r;
)
else if (samt:
{
0001 6&samt<=70000)
r=0.087
comm=samt*r;
)
else
{
r=0.10;
comm=samt*r;
)
System.out.printin("Sale Amount
system.out.printin(*Commission Rate:"+r);
+samt) 7
System.out.print1n (“Commission Amount: “+comm) ¢
)
)
Variable Description
Variable name Data type Description
samt double to accept the sale amount
comm. double to store the commission amount
r double to store the rate percentage
Indian Railways has different concessions in ticket cost as per the following criteria:
Category of Persons | Percentage of Concession
T. Disabled Passenger 15%
2. Patient 50%
3. Senior Citizen 40%
4, Awardee 30%
5, Others Nil
Write a program to input cost of ticket and category of persons from the options given
in the table. Calculate and display the cost of the ticket paid by the passenger after
availing the concession. a
import java.util.*
Ans:
class Railway
{
|
|‘Model Test Papers wii f (253,
public static void main(String args{])
{
Scanner sc=new Scanner (System. in);
int ch;
double to;
System.out.print1n("Enter option for Concession”);
system.out.print1n("1,Disabled Passenger”)?
System.out.print1n("2. Patients”)
system.out.print1n("3.Senior Citizen”);
System.out.print1n("4.Awardee”) ;
System. out.println("5.Others”) 7
ch=sc.nextInt ();
System.out.printin ("Enter cost of the ticket”);
tc=sc.nextDouble() ;
switch (ch)
{
case 1:
System.out.print1n(*Ticket Cost with Concessio!
+ (te-te*0.75))7
break;
case 2:
System.out.print1n ("Ticket Cost with Concession:”+(tc-te*0.50));
break;
case 3:
System.out.printin ("Ticket Cost with Concession:”+(te-tc*0.40));
break;
case 4:
system.out.println ("Ticket Cost with Concession:”+(te-te*0.30))7
break;
case 5:
system.out printin("Ticket Cost with No Concession:Ӣ#tc);
break;
defaul
system.out.printIn ("Invalid Category Entered.”);
Variable Description
Variable Name Data Type Description
ch int to store category choice
te double to store cost of ticketICSE Computer Applications Papers
Write a program to display the first 10 prime numbers. U5)
Ans: class Prime
q
public static void main(String args(])
(
int num=1,3,c=1,cl;
while (c<=10)
{
c=0;
for (j=1;}<=num; j++)
(
if (num?j==0)
cltt;
)
if (ec)
{
2)
System.out.printin (i)?
ott:
)
num++;
i
}
)
Variable Description
Variable Name Data Type Description
num int to store number to check prime
rd int to count prime numbers
i int to run loop for factors
cl int to count the factorsModel Test Paper
(Solved)
SECTION A (40 Marks)
Attempt all questions.
(QUESTION 1
Choose the correct answer and write the correct option. (20)
(i) Return data type of isLetterOrDigit (char) is:
(a) int
(6) char
(©) double
(d) boolean
Ans: (d) boolean
(ii) The operator which works on two operands:
(a) ternary
(6) unary
() binary
(d) relational
Ans: (c) binary
(iii) Give the output of the following String method:
Ans:
(iv)
Ans:
‘System.out.print((‘La Martiniere”. substring(0,5))+*rtiniere”);
(a) La Martiniere
(b) La rtiniere
(c) La Mrtiniere
(d) La artiniere
(a) La Martiniere
The ______ have the special meaning for java compiler.
(a) Identifier
(b) Methods
(c) Package
(d) Keywords
(a) Keywords- ICSE Computer Applications Papers
fw - weeds dimensonal array with size N what will be the last index position?
by Net
co NI
ad N2
Ans: (c) Nel
‘wu Output of the following statement
String n="good”,
String m="bye".
System. out printin concatim))
a) good bye
b) Good Bye
fc) goodbye
d) goodBye
Ans: (c) goodbye
(ou) What is the final value stored in variable k?
double s=Math.sqrt(Math.max(64.0,81.0));
System.out.print(s)
a8
b) 80
to 9
id) 9.0
Ans: (d) 9.00
(wus) Give the output of the following.
int a=2,b=6,c=3.
int re(secieb +-a)e(e++);
fa) 12
(ob) Id
(i 15
(d) 11
Ans: ic) 15
rad 6+ 1 4= IS]
(ax) Choose the odd one
ta) Robust
th) Platform Independent
te) Object Oriented
(d) Abstraction
Ans: id) Abstraction
INote: options (a, 1b) and e) are features of Java where option(d) Abstraction is OOPs feature)Model Test Papers
(x) What is the output of the following code?
int i;
forli=1;i<=6;i*=2);
System.out.printli+2);
fa) 3468
(b) 348
(c) 346
(d) 34610
Ans: (c) 346
(xi) Full form of API:
“7 (a) Advanced Programming Interface
(b) Application Programming Interface
(c) Application Procedure Interface
(d) None of the above
‘Ans: (b) Application Programming Interface.
(xii) The element on ala.length-3) of the array (2,4,8,10,16, 18,201:
(a) 10
(b) 16
() 18
(d) 20
Ans: (b) 16
[Note: a[7-3]=al4]=16]
(xiii) What is the size(bits) of float and double in java?
(a) 32 and 64
(b) 32 and 32
(c) 64 and 64
(d) 64 and 32
Ans: (a) 32 and 64
Da What is the output of the following code?
byte x=127;
att
xt;
System.out print(x);
(a) 129
(b) 128
(o) -127
(@) 127
Ans: (c) -127
INote: range of byte data in java is -128 to 127 and it is cyclic in nature.]
(xv)
lect the valid statement.
(a) char [] ch=new char(5)
(b) char [J ch=new charl5]
(ce) char [J ch=new char0258
(d) char [] ch=new char{]
Ans: (b) char [] ch=new char{5}
(xvi) When an array is passed to a method, what does the method receive?
(a) The reference of the array
(b) The copy of the array
(c) Length of the array
(d) Copy of first element of the array
Ans: (a) The reference of the array
Lvii) When is the object created with new keyword?
“ (q) At run time
ICSE Computer Applications Papers
(b) At compile time
(c) Depends on the code
(d) None of the above
Ans: (a) At run time
(xviti) To which of the following does the class String belong to?
(a) Java.string
() Java.util;
(©) Java.lang
(d) Java.io
Ans: (c) Java.lang
(xix) Identify the return type of a method that does not return any value.
(a) int
(b) void
(©) double
(d) None of the above
Ans: (b) void
(ax) Identify the keyword which can not be used for constructor.
(a) public
(b) private
(c) protected
(d) static
(d) static
fo]
7 sd
(i) What is meant by an infinite loop? Give an example. 21
Ans: The loop which has no end is known as an infinite loop.
Ex: for(int i=)
{
Model Test Papers 259
(ii) What is the value of i after the following code snippet executes? [2]
int i=17;
Ans:
(iii)
Ans:
(iv)
Ans.
w)
Ans:
(wi)
Ans:
(vii)
Ans:
(viii)
Ans:
(ix)
Ans:
system.out.print(i#+ + +i);
19
What are methods? How are these related to an object? (2
‘A method is an operation associated to an object. The behaviour of an object is
represented through associated functions, which are called methods.
State the difference between = and (2)
(i) It is an assignment operator. (i) It is a relational operator.
(ii) Ex: a=5; assigns the value (ii) Ex: compares variable a's
5 to the variable a. value with 5 and checks whether
it equals 5 or not.
Write the output of the following statements. [2]
String s="one two three”;
int p=s.indexOf('t’);
int pl=s.indexOf(‘t’,7)i
System.out.print (pos+” “+pos1);
48
Explain any two types of access specifier. (2]
The two types of access specifiers are the following:
Public: The data members with public access specifiers are accessible within the
package as well outside the package to the subclass and non-subclass.
Private: The data members with private access specifiers are accessible only within
the class where they are declared.
What are reusability features of Java and how does Java implement it? (2)
Object-oriented programming languages have an important feature of reusability.
‘The term means that the already written code can be reused by other programs.
In Java, it is implemented by using the concept of packages.
Assign the value of pi (ie, 3.142) to a variable with requisite data type. (2)
double pi=3.1427
What do you mean by a temporary instance of a class? (2)
‘A temporary instance of a class means an anonymous object (object having no name)
of the class and which is shortlived. Its benefit is when an object is required only
for a very short time.260
(x)
Ans:
QUESTION
Ans:
ICSE Computer Applications Papers
Differentiate between call by value and call by reference. (2]
L Call by value | Call by reference |
i) It is the technique of calling a (i) It is the technique of calling a
method passing primitive data type method passing object as arguments.
value as arguments to the method. to the method. Any changes made
Any changes made to the arguments to the arguments within the called
within the called procedure have no procedure reflects back to the actual
effect on the actual arguments. arguments.
i) It is a pure function. (ii) Tt is an impure function.
SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of programs in either BlueJ environment
or any program environment with Java as the base. Each program should be
written using Variable Descriptions /Mnemonic Codes such that the logic of the
program is clearly depicted. Flowcharts and Algorithms are not required.
Define a class with the following specifications: 5)
Class name : Number
Member Variable
int num : to store an integer value
intr to store reverse of the number num
Member Methods
Number (int n) : parameterised constructor to assign num=n
void sumdigit) : display number's digits sum
void reverse() : reverse the number num
boolean check() — : returns true if number is a palindromic number else returns false.
import java.util.*;
class Number
{
int num, rz
Number (int n)
(
num
r=0}Model Test Papers i : : :
void sumdigit ()
(
int copy=num,d,s=0;
while (copy!=0)
(
d=copy#10;
s=std;
copy=copy/10;
}
System.out.println("Digits Sum:”+s);
)
void reverse()
(
int d,copy;
copy=num;
while (copy!=0)
{
d=copy310;
r=r*10+d;
copy=copy/10;
}
boolean check ()
(
if (num==r)
return true;
else
return false;
)
public static void main(String args{])
{
Scanner sc=new Scannex (System. in);
int ni
system.out.println ("Enter any number:”);
nesc-nextInt (07
Number ob=new Number1234 (n) ;
ob.sumdigit ()7
ob. reverse ()i
if (ob. check ()==true)
system.out-printin("It is Palindromic Number”);
else262 ICSE Computer Applications Papers
System.out.print1n("It is not a Palindromic Number”);
Variable Description
Variable Name Data Type Description |
mum | int To store the number
r int To store reverse of the number
copy int To store the number temporarily
a int To store digit of the number
s int To store sum of digits
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 (n) entered by the user.
(15)
Ans: import java.util.
class sumInteger
public static void main(String args(])
(
Scanner sc=new Scanner (System. in);
int n,sn=0,se=0,s0=0,num, i;
System.out.print1n("Enter number of integers”);
ne=sc.nextInt ();
pisen;it+)
for (
‘
System.out.printin (“Enter any number”)
num=sc.nextInt () 7
if (num<0)
s!
sn+num;
else if (num>0sanum’2!=0)
i
System.out-println ("Sum of negative numbers:”+sn);
Sum of
system. out.-print1n( positive even numbers:”+se) ;
system.out-printin("Sum of positive odd numbers: ”+so) ;Test 4
(eee Perini ee ea ae
Variable Description
Variable name Data type Description
2 int to accept the integer
i int to run the loop
sn int to store the sum of negative numbers
80. int to store the sum of positive odd numbers
se int to store the sum of positive even numbers
Write a program to enter n students’ names and arrange the names in ascending order.
[Using Bubble Sort] (15)
Ans: import java.util.*;
class nameSort
{
public static void main(String args{])
{
Scanner sc=new Scanner (System.in);
int n,i,d?
System.out.println ("Enter the number of students:
n=Integer.parseInt (in.readLine())i
ew Stringin],t7
String nal
for (i=0;icnsit+)
(
system.out.println ("Enter your name”);
na[i]=in.readbine ()
}
system. out.printin(
for (i=0;icnzit+)
{
“The unsorted name list”);
system.out.printin(na[i]) 7
)
for (i=0;icn-Lsit+)
{
init)
if (na(}] -compareTo(na[j+1]) >0)
{
tenalil
a (jell s—
}
}
System.out.println(*The sorted name list”);
for (i=O;icn;i++)
ystem.out .printIn(nalil);
Variable Description
Variable name Data type Description ~]
2 int to accept the number of students
nal] String to accept name of the students
t String to store the name temporarily
ij int to run the loop
Define a class to accept n number of words in an array and display each word
swapping its first and last characters. (15)
J.length()-1);Model Test Papers
nti
i ewL) y
ubstring(1,w{il
System.out.println("Original Word :”+w[i]+”
)+ch
Modified Word
Variable Description
Variable Name | Data Type Description
wi) String ‘An array to store words
wi String | To store modified word
n int ‘To store size of the array
i int To run the loop
chi char ‘To store the first character
ch2 char ‘To store the last character
A library charges fine for late
of days taken to return a book to
the total fine charged. Fine is calculated based on the given conditions.
submission of books. Write a program to input number
the library after the due date and calculate and display
(15)
‘Number of days Fine/Day (in?)
First 2 Nil
Next 5 2.50
Next 7 4.00
Next 10 7.50
Above 24 10.00
Ans: import java.util.*7
class Library
(
public static void main(String args(1)
Scanner sc=new Scanner (System.in);
int d:
double £=0.07
system.out .printin (“Enter
c.nextInt (7
if (d<=2)
£=0.07
else if (d<=7)
£22404 (d-2) *2-507
number of days taken to return the book”);266 ICSE Computer Applications Papers
(d-14) 97.502
7*4.0+10*7.504 (d-24) *10.07
Total fine charged: "+£) 7
Variable Description
| Variable Name Data Type Description
| d | int ‘to store number of days
| f double to store total fine charged
Define a class to input name and area pin code for n number of users and input a
pin code to search and display the names of the users residing at the searched pin
code. If no such pin code found then display the message “No user resides at this
pin code.” (15)
@ main(String args{])
er (System.in);
in(*Input number of users”);
new String[n];
zing[n}, per
t-printin("Input Name of the user”);
nam se next i
ine etneattca el :
Input Area Pin Code of the user”)?Model Test Papers
)
System.out.print1n("Input the poncode to search”);
po=se.next (17
for (i=O;i=10;i/ 10)
(b) fortint i=10;i<=100;i+=10)
(c) for(int i=1;i<:
(d) for(int i=10;i<=100;i*=10)
(a) for(int i=100;i>=10;/10)
The first option is not valid as i/10 is not declared correctly. The correct statement
will be: for(int i=100;i>=10;i=i/10)]
7)
(Note:
(vi)
Ans:
(vii)
Ans:
(viii)
What is the output of the following code:
short x=32767;
xtty
System.out.print(x);
(a) 32768
(b) 32767
(c) -32768
(d) -32767
(©) -82768
In java short data range is from -32768 to 32,767 and its cyclic in nature]
Output of the following statement:
String n="5";
System.out.print(1+20+n+1+20);
(a) 47
(b) 1215120
(©) 215120
(@) 21521
(c) 215120
What is the final value stored in variable k?
double s=Math.floor(Math.max(2.34,4.67));
‘System.out.print(s);
@ 6
(b) 5.0
() 40
@4
(c) 4.00
Give the output of the following:
double x=2.5;
xta10+ +44 +
() 115a ee se
Ans: (b) 9.5
[Note: x=2.5+(10 + 3.5 +3.5 -10) = 2.5+7.0=9.5)
(ix) An array af)=(1,2,3,4,5,6) is given. What will be the result of a[2]+1+a[4-1]?
(a) 6
7
8
ws
Ans: (c) 8
[Note: a{2]+1+a[3}=3+1+4=8]
(x) The library method equalslgnoreCase () returns
(a) int
(b) boolean
(©) char
(d) string
Ans: (b) boolean
(xi) Identify the keyword among the following that makes a variable belong to a class
rather than being defined for each object of its class.
(@) final
(b) public
(ce) static
(d) private
Ans: (c) static
(xii) Find the value of num{1] after execution of the following code:
int num{}=(0,2,4,1,3);
fortint i=O;sicnum.length;i++)
i
numli}=num{(numfiJ+3) % num. length];
1
fa) 1
(b) 2
fo 3
(d) 4
Ans: (a) 1
Working
fal numi[i]
0 | num(0}=num[(num{0}+3)%5)
=num({(0+3)%5]=num[3]=1
1] num{1J=num{(num[1)}+3)%5) 1
=num([(2+3)%5)=num|[0}=:NR RR apemmmnne ni ce a
(xii)
Ans:
(xiv)
Ans:
(xv)
(xvi)
Ans:
(xvii)
Ans:
[Not
(xviii)
Ans:
_______ is not @ Wrapper class.
(a) Byte
(b) char
(c) Long
(d) Float
(b) char
Given array 1,4, 2, 5, 12, 3 what will be
the array after 2 passes of bubble sort for
ascending order.
(a) 1,2, 45,3, 12
@) 1, 2, 4,3, 5, 2
() 1, 24, 5,12, 3
(d) None of the above
(b) 1,2,4,3,5,12
‘Any array allows you to store elements with data type only.
(a) float
() long
(©) int
(@) same
(d) same
Ist PASS
2nd PASS
variables of a class may have different values for different objects.
(@) Local
(b) Instance
() Class
(d) Argument
(b) Instance
Number of primitive data types in java:
(a) 6
() 7
() 8
@9
8
The eight primitives in java are intbyte,shortlong float,double,booleand and char]
What does the following string do to given strl:
String str1="Examination”.replace(‘a’,e);
(a) Replaces all occurrence of ‘a’ with ‘e’
(b) Replaces first occurrence of ‘a’ with ‘e’
(c) Replaces all occurrence of @” with ‘a’
(a) Replaces first occurrence of @” with ‘a’
(b) Replaces first occurrence of ‘a’ with ‘e’ao
imix: Pick the odd one out
a) nextInt’
by nextDouble:
fe) nextString!
nat
Ans ic) nextString:
[Note: options a, 6 and d are valid input method where option b ie., nextString () is an
invalid String input method.)
‘xx; A loop within a loop is termed as.
‘a; Infinite loop
(by Null loop
(c) Nested loop
id) Delay loop
Ans: ‘c) Nested loop
“wy
fii) System
‘ivy
Ans: (i) omput
i 4
(ai) Applicationster
(iv) false
(ii) What is the significance of default in a switch case? 2)
‘Ans: The default is 2 special case in a switch statement which is automatically followed
if no case matches with the given switch value.
) What will be the result of the given expression, if p=10 initially. (2)
(i) (sp) + (prt) 2104
fii) (pst) +4%p<=407
Ans: (i) true
(ii) false
(iv) What do you mean by protected specifier? 2
Ans: Protected methods and fields can only be accessed within classes of the same package
and to the subclasses outside the package.ime ae Ri mney a a
(w) Write the Java expressions for the following arithmetic expressions. 2)
) 2x
ii)
Ans: ssqrt (2)*:
(i) dou!
=Math.exp (x);
(vi) What do you mean by encapsulation? ita)
‘Ans: Encapsulation is the act of combining both data and the functions that operate on
the data under a single unit.
(vii) Name the keyword that: [2]
(i is used for allocating memory to an array.
(ii) causes the control to transfer back to the method call.
Ans: (i) new
(ii) return
(viii) Rewrite the given snippet using do-while. (2)
int i,p
for (i=1;i<=20
t
p=ptis
}
System. out.println(p) +
peptiz
itt
}while (i<=20)7
(ix) If, array ()=(1,9/8/5/2}7 2
(i) What is array. length ()?
(ii), What is array(2)?
Ans: (i) 5
i) 8
(x) Write any two characteristics of Java. 7
Ans: The characteristies of Java are
(i) Write Once Run Anywhere (WORA)
(ii) Platform independencezs ICSE Computer Applications Papers
SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of programs in either Blued environment
or any program environment with Java as the base. Each program should be
written using Variable Descriptions /Mnemonic Codes such that the logic of the
program is clearly depicted. Flowcharts and Algorithms are not required.
to overload the method disp as follows
A
AB
ABC
ABCD
void displint n) _: to check whether the number is a Special number.
A number is Special if the digits factorial sum of the number
is equal to the original number.
Ex: 158=1!+5!43!=1+125+27
Void dispiint xint p) : to display xp without using any library function
Ans:while (copy
{
decopy10;
f-1;
for (j=17j<=
{
itt)
feEthe
system.out.printin("It is a Special Number”);
else
system.out-printin("It is a Special Number”);
}
void disp(int x,int p)
{
int i,num=1;
for(i pitt)
{
num=num*x;
)
system.out.print ("x*p:”+num) 7
,
public static void main(String args{})
{
scanner sc=new Scanner (System. in);
int x,Prns
overloadi23 ob=new Overload123();
ob.disp (0
gystem.out.printin (“Enter the value of n”);
cenextInt ()7
ob. disp(n)i
gysten.out.printin ("Enter base value x and exponent value
Pp’):
xesc-nextint ()F
pesc-nextint ()7
ob.disp(x/P)ia eae
Variable Description
Variable Name | Data Type Description
, int ‘To run the loop
j int To run the loop
d int To store digit from the number
‘ int To store program flow control
7 int To sore digits sum
copy int ‘To store number temporarily
x int To store base value
P int To store power value.
Write a program to store 20 different names along with corresponding telephone
numbers. Enter a name from the console and search whether the name is present
or not. If the name is present then display the name along with the phone number,
otherwise display an appropriate message using ‘linear search’ technique. (15)
Ans: import java.util.*;
class teleBook
{
public static void main(String args[])
f
Scanner sc=new Scanner (System. in);
String na[]=new String(20],name;
long phno{}=new long{20];
int i, £=0;
System.out.println("Enter names and telephone numbers of 20
users”);
for (i=0;i<20;i++)
i
na[i]=se.nextLine() i
phno[i]=sc.nextLong()i
)
System. out.printin("Enter the name to display the phone number”) ;
name=sc.nextLine () 7
for (i=0;i<207i++)
{
if (na[i]-equals (name) }mene ee
}
if (f==1)
System.out .println("The
else
System.out.println("No such name
Variable Description
T
Variable name Data type Description
nal} String to accept names of 20 users
phnol) long to accept telephone numbers of 20 users
name String to accept the name to search
i int to run the loop
f int to store the state of the condition, ie true
or false, or 1 or 0
Write a menu-driven program to display the following. (15)
1. To check palindrome numbers
2. To check Armstrong numbers
3. To check special numbers
4. To check perfect numbers
Use methods with required parameters to check the numbers.
Ans: import java.util.*;
class numberCheck
{
kealin(int 1)
public void
int r=0,d,num;
while (num!
i
de=n¢107
rer*lotd?
n=n/103
'
if (r==num)
system.out.println(*Palindrome Number”) ;cab ICSE Computer Applications Papers
Be aaa ES
Palindrome Number")
Syatom.out.print in (Net a
)
public void checkArms (int a)
(
int d,s=0,numz
pumen
while (nt=0)
(
dent10;
seat (int)Math.pow(d, 3) i
nen/10;
pum)
tem.out printLn ("Armstrong Number”) 7
System.out.print1n(*Not an Armstrong Number”) ;
)
public void checkSpecial (int n)
{
int £,i,s=0,d,num;
num=n;
while (n!=0)
(
103
pitt)
{
f=ftiz
}
s=stf;
n=n/10;
)
if (s==num)
system.out.print1n("Special Number”);
else
system.out.print1n(*Not a Special Number”);
J
public void checkPerfect (int n)Model Test Papers 29
{
int i,s=0;
for(i
‘
Lpicnsitty
if indi
=0)
s=stiz
}
if(s
n)
System.out.printin (“Perfect Number”);
else
System.out.print1n (“Not a Perfect Number”);
atic void main(String args{])
Scanner 5
nner (System. in);
numberCheck ob=new numberCheck ();
int ch,ng
System.out.print1n("Enter any number”);
nese.nextInt ()i
system. out.print1n("Enter your choice”);
System.out.print1n("1.To check Palindrome”);
System.out.print1n("2.To check Armstrong”);
system. out.print1n("3.To check Special”);
system.out.print1n("4.To check Perfect”);
ch=se.nextInt ();
switch (ch)
{
case
ob.checkPalin(n);
break;
case 2:
ob.checkArms (n) 7
break; |
case 3:
ob.checkSpecial (n);
break;
case 4:
ob.checkPerfect (n) i
break;ICSE Computer Applications Papers
ee ee
default:
System.out.printin ("Wrong Choice");
Variable Description
Variable name Data type Description
n int to accept the number
ch int to accept the choice
4 int to store the digit of a number
num int to store the number temporarily
r int to store the reverse of the number
i int to run the loop
f int to store the factorial
s int to store the sum of the factorial/factors
QUESTION $$
You can encode or decode a string in many ways. One of the simplest ways to replace
each letter by a letter at a fixed distance ahead or behind in the alphabet, where
the alphabet is assumed to wrap around (i.e ‘A’ follows ‘2’) eg., Given String “Mr
Sharat Chandran” and encode=3, means each character moves three characters ahead.
Thus, new String : Pu Vkdudw Fhdqgudg.
Write a program in Java to accept a string and display the new string after
encoding = 2, which means each character moves two characters ahead. (15)
Sample Input: Ashish Kumar Sinha
Sample Output: Cujkuj Mxoct Ukpje
Ans: import java.util.*;
class Encode
{
public static void main(String args{])
{
Scanner sc=new Scanner (System.in) +
String s,es="";
char ch;
int ayi
system.out.println("Enter any sentence”);
snextLine()7
For (is0;i=
(
AY &&Ch<="2") | | (ch>="a! G&Ch<="2"))
if (Character. isUpperCase (ch) )
{
if(c
rar)
essest/B
else if(ch=
y")
es=est/ A’;
else
{
a=(int) ch;
azat2;
es=es+(char)a;
else if (Character.isLowerCase (ch) )
(
if (ch=="2")
essest'b!
else if(ch=="y’)
es=est/a’;
else
arat2;
essest (char) ai
tes);
System.out.printIn("The encoded sentence
Variable Description
[_Variable name Data type Description
| 8 String to accept the sentence
| es String to accept the encoded sentence
| i int to run the loop
| ch char to store the character
a int to store the ASCII valuecheck its frequency in the string.
@ relevant message.
Ans: ocport
printin(“Input any vowel character (a,e,i,0,u)")F
scharat (0);
oLowerCase (v)
eae 4 4& visto! && vistul)
intln("Input character is not a vowel");
icw. length ();i++)
waw. toLowerCase();
if (w.charAt (i) ==v)
count++;
System.out.println ("Frequency of vowel character “+v+" i
Variable Description
{ Variable Name | Data Type | Description
| w | String To store a word
| v char To store vowel character
| count int ‘To count the vowel character
L i int To run the loopWrite a program to display the sum of the given series. 05)
(a) 1+ (1+2)+(14+24+3)4+ (1424344)... n terms
() 1+ * D+ *2*3 4 (1* 243% 4) 4... 0 trems
‘Ans: (a) import java.util.*;
class sumSeries
{
public static void main(String args{1)
‘
Scanner sc=new Scanner (System. in):
int n,i,s=0,si=
System.out.print1n("Enter the value of n in the series”);
nesc.nextInt ();
for (i=
{
pisen;it+)
s=stiz
sl=sits;
)
System.out.println("Sum of Series:”+s1);
Variable Description
Variable Name Data Type Description
i int to run the loop
n int to store the value of n in the series
s int to store sum of each term of the series
sl int to store sum of all the terms in the series
Ans: (b) import java.util.*7
class sumSeries
public static void main(String args(])
r
Scanner sc=new Scanner (System.in);
18-07
system.out.print1n("Enter the value of n in the series”);
int n,i,p=
n=sc.nextInt ()7
itt)p=pti:
}
System.out.printin("sum of Series:"+s);
Variable Description
Mi tdecctede ied Data Type Description
i int to run the loop
n int to store the value of n in the series
P int to store value of each term of the series
8 int to store sum of all the terms in the series