Page 40 - IP
P. 40
(b) Will the output from the following two code be any different? 2
First Code:
int x=2,y=40;
while(y<=x) {
jTextField1.setText(""+x);
x=x+8;
}
Second Code :
int x=2,y=40;
do {
jTextField1.setText(""+x);
x=x+8;
} while(y<=x);
Give reasons for your answer.
OR
Predict the output of the following code:
int n=4,f=0,i;
for(i=1;i<=n;i++)
{
f=f*i;
}
jTextField1.setText(""+f);
jTextField2.setText(""+i);
Ans: Yes it will be different as in First Code there will be no output while in Second
Code the output will be 2 because in while loop condition is false in the
beginning so control will not come inside the loop even for once while in do
while loop, loop will be executed at least once even if the condition is false.
(1 Mark for correct answer)
(1 Mark for correct explanations)
OR
Output:
0
5
(1 Mark for each correct answer)
(c) Dev, a website designer with “Creative Designers Pvt. Ltd.” has written the 4
following code. Observe the code given below and answer the following
questions:
<company>
<employee eid=1>
<name>Albert</name>
<dept deptid=“d1”>Computer</dept>
</employee>
<employee eid=2>
<name>Manisha</name>
<dept deptid=“d2”>Accounts</dept>
</employee>
</company>
3