ICSE Paper 2005: Computer Applications
ICSE Paper 2005: Computer Applications
n = 5 + 2. 5
n = 7.5
Qu estio n 2.
(a) Espl.aiil t_he term fo r loop with an example.
( b ) H?wt i.s a C'om pound statement ? Give an example.
(d ,.:::toi <" th t· difference between Constructor and Method.
(d) ,.:::oft· O ' it' .~imilo rity and one d ifference between while and do while loop.
1006 I ICSE La.s f IO Years S olved Paper s ◄
(e) Expla in , with the h e lp of An e xAmpl e , t h e purpo se of de fau lt i n
;:i
statem ent. ' \\ .
Answ er. fir
(a) for loop : It is a state m ent tha t rep eats t he proces s for fixed
nri r f
E.g. for (i = 1; i < = 10; i++) . ' tI
.
brace s 1s known as compo und statem ents. ' f cur
E.g. void m ( )
{
int n =5;
m = n *n;
}
(c) Cons truct or Meth od
(1) Class name and constr uctor name (1) Can have any name.
should be same .
(2) Is gener ally used for initial izing (2) Can do any type of calcula tion
data memb ers.
or printing.
(3) It has no return type. (3) It has return type.
(4) It is called autom aticall y. (4) It has to be invoke d.
(d) while and do while both are used to repeat the proces s as long as user
wants.
The differe nce betwe en while and do while is that while check s the
condition
first where as do while check s the condit ion at the end. So, do while
performs
the proces s once at any cost.
E.g. while do while
int i = 11; int i = 11;
while (i < 11) do
{ {
Syste m.out .print (i); System .out println (i);
i++; i++;
} }
Syste m.out .print ("**"); while (i < 11);
Syste m.out .print {"**");
outpu t : 11 ·
**
(e) defau lt is option al in .switc h case but it is used only when all the
cases are
false.
E.g. int ch= 12;
switch (ch)
J
- 1
,-,
1ru
20 0 ;1
Cnmpufer /i pp f, cnl 'n ~c:
case 1 :
System.out.print ("Yes'') ,· 'oren
-
1<;
case 2 :
System.out.print ("No"); b rea k ;
case 3 :
System.out.pr int ("OK'') ; break ;
default:
System.out.print("Sorry'');
}
Output will be Sorry.
because value of ch is 12 which does not m atc h with an y of th e cae Ps
Question 3.
(a) What will be the output of the following, if x = 5 initially ?
(i) 5 * ++x;
~ 5*~~ ~
(b) What is the output of the following ?
char c = '.A '·,
short m = 26;
int n = c+m;
System.out.println(n); [2]
(c) Explain the meaning of break and continue statements. [3]
(d) (i) What is call by value ?
(ii) How are the following passed ?
(1) Primitive types.
(2) Reference types. [3]
(e) Enter any two variables through constructor parameters and write a program
to swap and print the values. [4]
(f) What do the following functions return for :
String x = ''hello ':·
·
S tring y = "wor ld";
(i) Sy stem.out.println(x + y);
(ii) S ystem.out.println(x.len gth ( ));
(iii) Sy stem.out.println(x.char At(3));
(iv) S ystem.out.println(x.equ als(y)); (4 ]
(g) Differen tiate between toLowerCase() and toUpperCase() methods. (2 ]
Answer.
(a) (i) 30 , (ii) 25
(b) 91
(c) Break is to stop the _loop process forcefully in between.
Continue is to keep on r~peating the process skipping a · particular iteration.
E ·::-··
CT r
1or c·1 = 1 ,• i < = 5; 1 ++)
1'
if (i > 3)
break:
1008 I ICSE Last JO Years S olved Papers
else
System .out. pri ntln (i) ;
O u tµut :
2
:J
for (i = l; i < = 5; i ++)
'
\
if (i % 2 = = 0)
continue;
else
System.out .println (i);
\
'
Output: 1
3
5
(d) (i)
Call by value : This method copies the values of actual parameters ui,
formal parameters , the function creates its own copy of arguments. sr
whatever changes takes place, does not effect the original parameters.
(ii) (1) Call by value
(2) Call by reference
(e) class Sample
{
private int a, b;
Sample (int i, int j) //constructo r
{
a= i;
b = j;
},
void swap (int a, int b)
{
int temp;
temp= a;
a= b;
b = temp;
System.out .println (a + "" + b);
}
}
(f) (i) HelloWorld, (ii) 5, .(iii) l, (iv) false .
(g) toLowerCas e () ➔ This function converts the upper case letters in a qtring to
lower case letters.
toUpperCas e () ➔ This function converts the lower cas~ letters in a string to
upper case letters. ·
(both string and characters can be converted)
J
SECTION B (60 MArJ< q)
All
.e mpt c111 y fo",~ q11 p.c;: f ion 8 f rnm ' I H.-~ '';prf,on .
t:- ,tJ- ,:,r A ",;. ·
r
T he answers in ' ' ti· us· , ~sect10n
· 8h o11 ld ,·on .c;: 1,c;:
. f o f f 1J f' , ,' 1,,.,,a ro rn 1 " 1hc- hr1-:~
Q
en vr.,onment,
·, or any proJ1.rom r 11 11 ;,.,,,, m Pn t w,·,,' ·/ 0 1 o o~ r ,.r{J'.~
Eac h' pro0aram• .s·Iwu ld
,
be writt,en
.. . . I . tion 8 t J'1,( n ,:, mn111r
u s 1,11.J1. Varwhf P ~ p.c;rrip . J
, I
suet that the log 1.,c of the pro}{ r etm 1.,,c, r I NJf IY rf pp 1rfPI
Flow -Charts and Algorit.h,n ,c, a re not rpqu i red
Question 4. f-
.
wn e a c ass wit 1, name employee and ha.c;ic as i t .c; · a
t l . I . d ta mP m hP r . t o f i ,, d f ~
[_{ ~P
gross pay of an employee for the following allo wances an dNL u r f i nn . d
meaningful variables.
Dearness Allowance = 25% of Basic Pay
House Rent Allowance :::! 15% of Basic Pay
Provident Fund = 8.33% of Basic Pay
Net pay = Basic Pay + Dearness Allowance + House R ent A llo wance
Gross Pay = Net Pay - Provident Fund. i[151
Answer.
class employee
{
private int basic;
void salary (int BS) //Enter salary and name
{
double DA, HR, PF, NP, GP;
basic= BS;
DA = (25.0/100) * basic;
HR = (15.0/100) * basic; //Calculating Gross
PF = (8.33/100) * basic;
NP= basic + DA + HR;
GP= NP - PF;
System.out.pri ntln ("Gross pay" + GP);
}
"I.
J
Question 5.
Write a program to input any given string to calculate the total nunibe r of
characters and vowels present in the string and also reverse the strz'.ng :
Example : INPUT
E nter s tring : .SNOWY
oz ·r p[TT .- Total number of characters 05
Number of vowels 01
Reverse string
YWONS
(15)
1010 I ICSE Last JO Years Solved Papers
l
Answer.
import java.io.*;
class progs
(System.in)); '
System.out.println ("Enter any String :'');
Str = br.readLine ( );
int i, len, ch = 0, VO = O;
char al;
//finding length;
len = Str. length ( );
String Rev;
for (i = len - 1; i > = O; i- -)
//Extracting character
{
al = Str.charAt (i);
Rev = Rev + al;
if (al== 'A' 11 al== 'E' I I al== 'I' I I al== 'O' I I al= '1Jl
VO++;
}
System.out.println ("Total no. of characters" + len);
System.out.println ("Number of vowels" + VO);
System.out.println ("Reverse string" + Rev);
}
}
Question 6.
Write a program using a function called area() to compute the area of a:
(i) circle (n * r 2) where n = 3.14
(ii) square (side * side)
(iii) rectangle (length * breadth)
Display the menu to output the area as per user's choice. [15]
Answer.
I/Program to find area
import java.io*;
public class compte
{
static long areaRectangle Oong sidel, long side2)
{
return (sidel *side2);
\
J