Adobe Scan 7 Nov 2024
Adobe Scan 7 Nov 2024
Question 1.
[ 20]
choose the correct answers to the questions from the given options.
(Do not copy the question, write the correct answers only.)
(a) logical operator (b) arithmetic operator (c) relational operator (d) cond\t\ona\ operator
{iv) When higher data type is converted to a corresponding lower· datatvpe , it is ca\\ed:
(a) Boxing (b) Unboxing (c) Explicit type conversion (d) Implicit type conversion
(vi) The method of Scanner class used to accept a character yalue is:
(a) nextChar() (b) nextCharacter() (c) nextline().charAt (O) (d} none of these
(a) logical error (b) syntax error (c) NaN (d) none of these
{a) syntax error (b) runtime error (c) logical error (d) no error
1
..)
(.XII _ _ _ _ _ _ are the sta tem
_ en ts in a pro gra m thata re no t ex ec ute d.
la) Co mm en ts (b) Va • ti
riables (c) Variable
Oescnp on (d) Loops
(xiii) Wh en the opera . . the y are ev alu ···· ··•· "·· in th e or
tors have the same ate d fro m ............ de r th ey appe-c.
pn on ty, ..... •
the expression.
A) rig ht to lef t B) lef
t to rig ht C) any of the d o) de pe nd s on the co
or er mp ile r
(xiv) Which principle
of OOP does 'exten
ding a class' ad he re
(a) Abstraction (b) to?
Encapsulation (c) Inh
eri tan ce (d} Po lym
orp his m
(xv) Wh at wil l be the
result of the fol low
ing sta tem en t?
Sy ste m. ou t.p rin tln(
3+ 3 •3 • 3+ 3);
(a) 57 (b) 33 (c) 10
8 (d) None of the se
(xvi) Which of the
fol low ing are pri mi tiv e da
ta typ es :
i. char ii. Integer iii.
flo at iv. do ub le
(a) Only I (b) Only ii
(c) Both i and ii (d)
No ne of the se
(xvii) Assertion: In Jav
a, the "st ati c" ke yw
ord is used to de cla
class and no t to ins re va ria ble s th at be
tances of the class. lon g to th e
Reason: By using the
"st ati c" ke yw ord , the
se va ria ble s ca n be
creating an instance accessed wi th ou
of the class. t
Which op tio n corre
ctly describes the
rel ati on sh ip be tw
ee n
As se rtio n an d Re
(a) Both Assertion as on ?
and Reason are tru
e, an d Reason is a
co rre ct ex pla na tio n of As se rtio
(b) Both Assertion n.
an d Reason are tru
e, bu t Reason is no
(c) Assertion is tru e, t a co rre ct ex pla na
bu t Reason is false tio n of As se rti
.
(d) Assertion is false on .
, bu t Reason is tru
e.
(xviii) Read the fol low
ing tex t, an <ic ho os
\n lav a the "fo e th
• l"' st.a
ter ne nt \s
e co rre ct an sw er
•
us ed to loo p-
Wh \ch of the fo\ Ul t• &Iv e •
\ow \ng \s tru e ab n co nd itio n Is
ou t th e "fo r" sta tru e
(a) \ni t\a \\z at\ on t
in for is op tio na ern en t In Jav a? •
l
{b) Co nd itio n in for
Is op t\o na l.
(c) lnc rem en t/D ea
em en t I.e . ste p is
op tio na l.
(d) All of the abov
e.
(xix) Assertk>n (A)
: An array varlable ls als
o kn ow n as subscri
Reason (R): In arrays pted variable.
, every ele me nt is
represented wi th
(a) Both Assertion the he lp of its ind
(A} and Reason (R) ividual Index.
are tru e and Reaso
(b} Both Assertion n (R) Is a correct ex
(A) and Reason (R) planation of As se
are tru e rtion (A)
and Reason (R) ls no
(c) Assertion (A} Is t a co rre ct ex pla na
tru e and Reason (R) tio n of Assertion(A
Is false )
(d) Assertion (A) is
false and Reason (R)
ls tru e
(xx) Which of the fol . statements corre
low ing ctly describes the be
havior of the Ma th.
ran do m( ) me tho d
ath random() ret um d Integer between O in Java7
(a} M • s a ran om (inclusive) and 1 (ex
clusive).
(b) Ma th. ran do m( ) d ble between o.o
returns a random (inclusive) and 1.0 (ex
ou clusive).
(c) Ma th. ran do m( ) d m boOlean value
generates a ran o .
(d) Ma th. ran do m( ) do m lon g value.
ret urn s a ran
2
,sdon 2.
2
-r . the Java expression for y=b-i3((b -4ac))/(2a)
,, write {2]
h expression when int x=2:
~~c$),./ (ii) Evaluate t e (2)
+x·
int y=x+x++ + ++X ,
. ode segment checks if the given year is a leap year or not. ( 2]
(iii) The following c
has errors. Fix the code so that it compiles and runs correctly.
However the code
. b<>Olean isOdd(int n){
public stat1c
; boolean result = False;
if (n9'2==1) result=true;
return result;
}
[2]
{iV) Harsh is trying to determine the average of three numbers.
However the following code segment is not giving the correct answer. How the program can
float numberl=in.nextFloat();
float number2=in.nextFloat();
float number2=in.nextFloat();
(v) What will be the value of count after the ~oJlowing code segment is.executed? [21
byte count = O;
for( ;count>=O; ){
count++;
(vi) Convert the following segment into equivalent for loop. (2]
int year;
year= 2023;
J
{
(vii) Name the two reserved words which are not keywords. [2)
3
(ix) When th . .
er e is no explic
it initiahzano h a t are t he default values set
n, w to r
variable in th
e follo wing cases?
(a) double
(b) boOlean
(x) Convert
th e following if . w itc h case st
else statemen
~ in to s at em en t [ 2]
lf(x==l)
System.out.p
rintln("one");
else if(x==2)
System.out
.println("two"
);
else
System.out.p
rintln("errorn
);
SECTION B
(6 0 M ar ks )
The answers (Answer any
in this section fo ur questio
should cons ns fr o m th is
ist o f th e pr S ec tio n. )
pr og ram environm ograms in e .
Each program it h e r BlueJ
should be w ent w it h java e n va ro n m
rit te n using as th e ba se . ent or any
variable de
sc ri pt io n/ m
th e program ne m on ic co .
is clearly de de s so th a
Q ue st io n 3. Flowcharts an pi ct ed . t th e lo g ic
d algorithm of
s are n o t re
Input a three qu ir ed .
digit numbe
A number is riand check
said to be Ju w he th er it is
pi ter number a Jupiter nu
~ .: .: :: , ~+ if it is compl m be r o r n o
t. U si ng vo [ 151
6=7 and 126 et ely divisible id Ju p it e r(
is divisi~le by by su m o f it in t n ).
4 7. s fi rs t a n d
la st d ig it .
~ ;\ ~ a pr og ra
m en te r a
U si ng \n t po si tiv e \n
su m l\n t n) te ge r. C om
. pu te an d
~ es t. \o nS re tu rn th
. e su m o
f al l p ri m
/;,. Oudenev e di gi ts
nu m be r \s a co n ta in
e d In th
th e nu m be po sl tw e In te ge e nu na
r. W rt te a pr r th at ls a pe
ogram to In rf ec t cu be
du de ne y\ \n pu t a nu m be r su ch th a t
t n) . an d ch ec k th e su m o .
Example: an d pr in t w f its di gi ts [1 5 ]
he th er It Is is eq ua l to
co ns id er th a D ud en ey th e cu b e
e nu m be r 51 number o ro o t 0 ~
2. r n o t us in
su m of di g\ g vo id
ts = S + 1 + 2 8
=
Cube ro ot of
11,.s su m of
51 2 = 8
di gi ts = Cub t o f N um be
e ro o r he nc e 51 2
is a ou de ne
y nu m be r
Q ue st io n&
.
W rit e a m en og
u dr iv en pr ra m to pe rf or m th e fo
llo w in g op er r1.sJ
at io ns as pe
. um In t n)
li) vo id s To pr in t th e • r us er •s c ho1• e·
l su m of th e c •
S :1+{1•2 )+
{1•2 • 3)+••• •• lt•2 •3 •se ries
..................+n
lii ) vo id di sp ···;···--~~;·~ )
\lowlng serie
1 12 12 3, \a yl ) To dlsp s us in g fo r
1234,........... av ...............,1 23 45 67 lo op :
, , ...... 89
W rit e m ai n th od using .... h se st at em en
me sw\tc ca t to execute
th e above m
et od .
4
Question 7.
da s without any fine, while
Apub\ic \ibrarv \ssues books, h' h a student can use for 7 V returning the book
w ,c ed ai.er specified days.
a une w·,\\ be charged only for excess days, if return. ": l1S1
Oesign a c\a~ library with the . ificanons:
following spec
C\ass name : library
Member variables / Data mem
bers: .
bname - to store the name of
the book issued.
days - to store the number of days taken to return the book.
extra - to store the extra days
after the specified days.
fine_amount - to store the amo
unt to be paid as fine.
Member methods:
void input() - to input the nam
e of the book and the number
return the book. of days taken to
void computefine() - to compute
the extra days taken to retu
days as per the given slabs: rn the book and calculate
the fine amount only for extr
a
Extra days
Charge per day
Upto 5days
~5
6 to 15 days
~10
Above 15 days
void display() - to display the
~o
name of the book, extra day
Now define a main() method s taken to return and the fine
to create an object and invo amount.
desired output. ke the above member metho
ds for obtaining the
Question 8.