[go: up one dir, main page]

0% found this document useful (0 votes)
22 views10 pages

XPaper16 (Solved)

Uploaded by

avnibhatt006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

XPaper16 (Solved)

Uploaded by

avnibhatt006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

STAGE 1

SAMPLE
QUESTION
PAPER1
Computer Applications
(Question-Answer)
A Highly Simulated Practice Questions Paper
for ICSE Class X Examination

General Instructions Time : 2 hrs MM : 100

• This paper is divided into two sections.


• Attempt 111 questions from Section A and any four questions from Section B.
• The intended marks for questions or parts of questions are given in bradcets[ ] .

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

(ii) Give the oucput of the following statement.


String myStrl ="He l lo";
String myStr2 ="Hello";
System.out.println(myStrl.compareTo(myStr2));
(a)O (b)l
(c)2 (d)ll
Ans. (a) compareTo( ) function compares the two values of the string and in the given code myStrl is
compared with myStr2 and if the values of string matched, it returns a Boolean value as 0. So, the
output ~f the given code is 0.
(iii) Array is a .......... .. data type.
(a) integer (b) string
(c) composite (d) mixed
Ans. (c) Array is composite data type. A composite data type is one whose values are composed of
component values (possibly values chosen from other data types).
(iv) Which of the following concept can be used for encapsulation?
(a) Wrapping data fields with methods
(b) Hiding data and internal methods using access modifiers in a class
(c) Using interfaces
( d) All of the above
Ans. (d) Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that
binds together code and the data it manipulates. It hides data and internal methods using access
modifiers in a class and using the interfaces.
(v) Variables that are shared by every instances of a class are ...... ...... .
(a) public variables (b) private variables
(c) instance variables (d) class variables
Ans. (d) Every instance of the class shares a class variable, which is in one fixed location in memory. Any
object can change the value of a class variable, but class variables can also be manipulated without
creating an instance of the class.
(vi) One benefit of encapsulation is ........... .
(a) the implementation of the class will be smaller.
(b) the implementation can be changed without changing programs that use the class.
(c) the interface of the class will be smaller.
(d) the interface can be changed without changing programs chat use the class.

,_ 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

(xviii) Constructor's syntax does not include


(a) return type (b) class name
(c) parenthesis (d) All of these
Ans. (a) Constructor's syntax does not include return type, since constructors never return a value.
{xix) Which of the following can be used to invoke another constructor in the same class?
(a) new() (b) static()
(c) thist) (d) complex()
Ans. (c) this() can be used to invoke another constructor in the same class. Also, this constructor can be
used to implement local chaining of constructors in a class.
(xx) These statements can be used to modify the behaviour of conditional and iterative
statements.
(a) Jump statements (b) Iterative statements
(c) Selection statements (d) Switch statements
Ans. (a) Jump statements can be used to modify the behaviour of conditional and iterative statements.
There are two types of jump statements as break and continue.

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.

• Common classes are FileReader • Common classes are FilelnputStream and


and FileWriter. FileOutputStream.

(iii) Write down the basic structure of a Java program. [2]


Ans. import package;
publi c class Name
L. I
Q)
public static void ma in(String args[J)
Cl.
(t'J I
Cl. //statements
c
.Q
t;
Q) (iv) What will be the output of the following, if a =7 initially? [2]
:::J
(a) 2* ++a +3 (b) 2* a++-3
Ci
Q) Ans. (a) 2*8+ 3=16+ 3=19 (b) 2 * 7 - 3 = 14 - 3 = 11
Cl. {v) Write a statement in Java for the following mathematical expression: [2]
E
C./)
(t'J
~{a 3 + b 3 )/2ab
Ans. x = Math. sqrt((Mat h.pow(a, 3) + Math.pow(b, 3))/2* a* b);
Sample Question Paper 1 15

(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

int f[J = new int[n + 2];


int i ;
f[OJ = 0;
f[l]=l;
for Ci= 2; i <= n; i++)
I
f[i] = f[i - 1) + f[i - 2] ;
I
retur tf f[n];

publi c static void main (Stri ng args[J)


I
intN=lO;
for (in ti= O; i < N: i++J
System.out.p r int (fib (i) + " " ) ;

4. Design a class HotelBooking wi th the following description : [15]


Class name : HotelBooking
Instance variables/Data members
String name To store the name of the customer
String type To store the type of room that customer wants to
double mobno : To store customer's mobile number
int amt To store basic amount of room
int totalamt To store the amount to be paid after updating the original amount
Member methods
void accept() To take input for name, type, mobile nwnber and amount
void update() : To update the amount as per the type selected
(extra amount to be added in the amount as follows)
Type of room Amount
Full_AC 4000
Partial_AC 3000
Cooler 2000
Normal 1000

~
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):

public static void main(String args[J) throws IOException


I
HotelSooking HB =new HotelSooking();
HS . ac cept() ;
HS.update() ;
HS.display{ ); ....
<1>
Q.
(ti
Q.
5. Write a Java program lo remove duplicate elements from an array. [15] c
0
Ans. import java.io.*: ~
V)
import java.util.* ; <1>
public class RemDup ::J
I
public static int removeDupElement (int arr[], int nJ
a
<1>
I Q.
if cn~o II n~1>
return n: E
(ti
int[] temp= new int[nJ : V')
int j = O;
18 Sample Q uest ion Papers ICSE Computer Applications Class X

for ( i nt i =O ; i <n - 1 ; i ++)


if (arr[i] != arr[i+l])
temp[j++J - arr[i];
temp[j++J = arr[n-1);
II Changing original array
for(int i=O; i<j; i++)
arr[iJ = temp[i];
return j;
t"
public static void main (String[] argsl
(
int arr[] = (10,20,20,30,30,40,50,501;
int length= arr.length;
length - removeOupElement(arr. length);
//printing array elements
for(int i-0; i<length; i++)
System.out.print(arr[i]+• ");

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" ) ;

Sys t em. out . pr intln () ;

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

Scanner sc =new Scanner(System . in);


System.out.print("lnput a number : ") ;
int num = sc . nextlnt();
int copy = num,d=O.sum=O;
Str ings= Integer.toString(num) ;
int len = s.length();
while(copy>O)
{ r
d=copy%10;
sum= sum+( int)Math.pow(d ,len ):
1en -
copy=copy 110;

ifCsum = num)
System.out.println( "Disarium Number.");
else
System.out.println( "Not a Disarium Number.");

You might also like