XPaper16 (Solved)
XPaper16 (Solved)
SAMPLE
QUESTION
PAPER1
Computer Applications
(Question-Answer)
A Highly Simulated Practice Questions Paper
for ICSE Class X Examination
Section-A
(Attempt all questions from this Section.)
1. Choose the correct answer and write the correct option. [20]
(i) Which is not a true statement about array?
(a) An array expands automatically when it is full.
(b) An array is allowed to contain duplicate values.
(c) An array understands the concept of ordered elements.
(d) An array uses a zero index to reference the first element.
Ans. (a) In Java, an array is an object which contains elements of a similar data type.
Additionally, the elements of an array are stored in a contiguous memory location. An
array is also allowed to contain duplicate values and uses a zero index to reference the
first element.
Forexample, int a[5]={3,4.5,6, 71;
In this, value of a[O] = 3,a[ 1) = 4, a[2] = 5,a[3) =6,a[4) =7
12 Sample Question Papers ICSE Computer Applications Class X
,_ Ans. (b) 'The implementation can be changed without changing programs that use the class' is one of the
benefit of encapsulation.
<.v
0.. (vii) ln Java, a library of classes is called ............ .
<t:I
Q.. (a) a folder (b) a package
c (c) a directory (d) an application
0
~
Q)
Ans. (b) In Java, a library of classes is called a package. Ajava package is a group of similar types of classes,
interfaces and sub-packages.
::J
CJ (viii) The order of the three top level elements of Java source file is
Q) (a) import, package, class (b) class, import, package
a. (c) package, import, class (d) Any order
E
<t:I
Ans. (c) Package in Java is a mechanism to encapsulate a group of classes, sub-packages and interfaces.
ti) So, to use a class we have to import a package first.
Sample Question Paper 1 13
(ix) Which of the following methods can be used to join two strings?
(a) trim( ) (b) concatenate( )
(c) concat( ) (d) join( )
Ans. (c) The Java String class concat( ) method combines specified string at the end of this string. It
returns a combined string. It is like appending another string.
(x) Give the output of the following functions.
String x="Computer":
String y="Applic~tions ":
System.out.println(x.index0f(x.charAt(4)));
(a)4 (b)5 (c)3 (d)2
Ans. (a) x.charAt(4) returns the character at index 4 of string x which is 'u'. First index of 'u' in xis 4, so
output is 4.
(xi) What is the final value stored in variable x?
double x = Math.ceil <Math . abs (- 7.3));
(a) 7.0 (b) 8.0 (c) 6.0 (d) 9.0
Ans. (b) Math.abs (- 7.3) returns 7.3 and 8.0 is the ceil value of 7.3.
(xii) How many types of print statements are there in Java?
(a)2 (b)3 (c)4 (d)5
Ans. (a) There are two types of print statements in Java as System.out.print() and System.out.println( ).
(xiii) Which of the following is a set of programs rhat rrJnsforms source code into byte
code?
(a) Java Source Code (b) Java Compiler
(c) Bytecode (d) Interpreter
Ans. (b) A Java compiler is a set of programs that transforms source code imo bytecode.
(xiv) It is a composite data type because it requires to use its attributes.
(a) class (b) object
(c) integer (d) array
Ans. (a) class is a composite data type because it requires to use its attributes. The class binds various
primitive types together for using them as a unit.
(xv) The keyword to create an object of a class is
(a) create (b) new (c) New (d) NEW
Ans. (b) For creation of an object dynamically. use new keyword.
.....
(xvi) To declare a method in Java, choose the required components.
(a) Modifier (b) Return type
8.
(c) Method name (d) All of these "'
a.
c
Ans. (d) Method is a collection of statements that are grouped together to perform coherent task or any .o
particular operation. To declare a method in Java, required components are modifier, return type,
method name, parameter list in parenrhesis, method body and method signature.
t;
C1'
:J
(xvii) It is used to implement class behaviours that are not affected by the state of any
instance.
C1
C1'
(a) static keyword (b) static data member a.
(c) static method (d) None of these E
Ans. (c) Java static method is used to implement class behaviours that are not affected by the state of any
instance. Java static methods have m;my restrictions over themselves. "'
V')
14 Sample Question Papers ICSE Computer Applications Class X
2. (i) State the number of bytes and bits occupied by a character array of 6 elements. [2]
Ans. One char data type takes 2 bytes.
Number of bytes occupied by char array [6] is
6x 2=12 bytes
1 byte = 8 bits
12 bytes= 12 x 8 = 96 bits
(ii) Differentiate between character stream and byte stream. [2]
Ans. Differences between character stream and byte stream are as follows :
Character Stream Byte Stream
• This stream is used to perform input • This stream is used to perform input and
and output for 16 bits unicode output for 8 bits data in byte format.
character in character format.
(vi) If a = 24, b =15, find the value of a+= b ++ *5/a++ +b. [2]
A ns. a+ = b + + * 5 I a++ + b
a=a+b++ * 5/ a++ +b
=24+ (15 * 5) / 24+16
= 24+(75/ 24)+16
=24+ 3+16
=43
(vii) What will the foijowing functions return? [2]
(a) Math . rnund (Math . pow (2 .5. 3)) ;
(b) Math.abs (Math.max (- 25 , 25)) ;
Ans. (a) 16 (b) 25
(viii) Give the output of the following string functions : [2]
(a) "LANGUAGE". replace ( 'A', '0' ) ;
(b) "PROGRAM" . compareTo ("Programme" ) ;
Ans. (a) LONGUOGE (b)-32
(ix) Write the return type of the following library functions. [2]
(a) isLetterOrDigit(char) (b) replace(char, char)
Ans. (a) Boolean (b) String
(x) Differentiate between the following code fragments and also give their output : [2]
(a) int f =1. i =2 ;
whil e(++i<5)
f *=i;
System. out .printl n(f ) ;
(b) int f =l, i=2 ;
do
{
f *=i;
while C++i<5) ;
System. out .println (f) ;
Ans. The difference in the given code fragments is code(b ) executes one time more than code (a), because
code (b) is implemented using do-while loop. do-while loop executes atleast once even if the while
condition is False, whereas in while loop, iL first checks the condition and then enter in the loop, if the
condition is True.
Output of Code ....
Q)
(a) 12 (b) 24 Q.
Section- B 'c°
Q.
0
(Attempt any four questions from this Section.)
~
Q)
3. Write a program in Java which prints fibonacci series using arrays. ::J
[Hint A series of numbers in which each number (Fibonacci number) is the sum of the two a
preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.] [15) ~
Ans. i mpo rt java.util .* ; Q.
public cla ss fibona cc i E
nJ
I (/')
stati c i nt f i b(i nt n)
16 Sample Question Papers ICSE Computer Applications Class X
~
void display() : To display all details of a cu'>tomer such as name, type, total amount
Q) and mobile number
0.. Also, define a main() method to create an object of the class and call the above member
nJ
tl. methods.
c Ans. import java. i o. *;
.Q import java.util .* ;
+-'
publ ic class HotelBooking
"' Q)
::::J
I
String name.type;
a Q)
double mobno:
int amt.totalamt;
0.. void accept() throws IOException
,,, CJ')
E
nJ
(
BufferedReader br =new BufferedReader(new InputStreamReader (System.in));
System.out . println( "Enter the name of the customer :" ) ;
.,
Sample Question Paper 1 17
name= br.readline();
System . out.println("Enter the type of room custome r wants to :") ;
type= br . readline();
System.out.printlnC"Enter the customer's mobile number : ") ;
mobno = Double . parseDouble(br.readline());
System.out.println("Enter the basic amount of room:");
amt= Integer.parselnt(br.readline());
void update() r
(
switch( type )
(
case • Ful l_AC" :
totalamt amt+4000;
break;
case "Partial_AC":
totalamt = amt+3000;
break;
case "Cooler":
totalamt = amt+2000:
break:
case "Normal":
totalamt amt+lOOO:
break:
void display( )
(
System . out.println( "Name: "+n ame) :
System .ou t.p rintlnC "Room type : "+tyoe ) :
System.out.printlnC"Mobile number:"+mobno):
System. out.println("Total amount:"+totnlamt):
6. Using the switch statement, write a menu driven program for the following: [15]
(i) l (ii) B
l2 BL
l 23 BLU
1234 B LUE
1234 5
Ans. import java.io . *;
import java.util .*;
public class Pattern
I
public static void mainCString args[J) throws IOException
I
InputStreamReader IR = new InputStreamReaderCSystem . in);
BufferedReader br = new BufferedReader(IR);
System.out.printlnC"Choose the correct choice:");
System.out.printlnC"l. To print the first pattern . . . ");
System.out.printlnC"2. To print the second pattern . . . ");
int ch~Integer.parselnt(br.readline());
switch Cch)
.._ I
8.
CV
case 1:
Scanner sc = new Scanner(System.in) ;
a.. System.out.printlnC"How many rows you want in this pattern?");
c: int rows = sc. nextlnt();
0
System.out.printlnC"Here is your pattern .. . . !!!");
t; forCint i=l;i<=rows;i++)
Q)
~ I
aQ) for( int j-l;j<=i ;j++)
(
Q. System.out.printCj+" ");
E
CV
(/)
System.out.println();
Sample Question Paper 1 19
break ;
case 2:
Strin g s="BLUE";
f or ( i nt i=l:i <=4;i++ )
(
f or ( int j =l ;j <-i ;j++ )
(
char re s=s . charAt (j - 1);
~y s tem.out.print(res+" \ t" ) ;
break;
defa ul t :
Sys tem.out . pr i ntln ( "Wrong choi ce" ) ;
7. Define a class to accept a string, convert it into lowercase and check whether the string is a
palindrome or not. [15]
A palindrome is a word which reads the same backward as forward.
Example: madam, racecar etc.
.Ans. i mport j ava . uti l .* ;
publ ic cl ass Pa l i ndrome
(
publ i c static void mai n(String [J args)
(
Stri ng st r , r ev - "" ;
Sca nner sc - new Sc anner (System. in);
Sys tem .out.println ( "Ente r a st r ing:" ) ;
str = sc. nextli ne () ;
str = st r .tol owe rC ase () ;
i nt l engt h - str . l ength() ;
for ( int i - 1eng t h - 1 ; i >- 0 ; i - -
rev= rev+ st r. cha rAt(i) ;
if Cstr. equ al s(rev ))
Sys t em.out.pr i ntln (s t r+" is a palindrome" ) ;
el se
Sys tem. out .pr i ntlnC st r+"is not a palindrome" ) ;
~
cu
a..
c:
8. A disarium number is a number in which the sum of the digits to the power of their respective 0
positive is equal to the number itself. t;
Q)
e.g. 135 =1 1 +3 2 +5 3 ~
Hence, 135 is a disarium number. 0
Design a class Dlsarium to check, if a given number is disarium number or not. [15] Q)
Q.
.Ans. i mport java . util . Sca nne r;
publ ic cla ss Dis arium
E
cu
I V')
pub l i c stat i c voi d main (St ring args [] )
20 Sample Question Papers ICSE Computer Applications Class X
ifCsum = num)
System.out.println( "Disarium Number.");
else
System.out.println( "Not a Disarium Number.");