Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Chapter 2

Revision Tour II

Mental Drill

A. Tick (

Ans. Technical errors

Ans. b.

Ans. b.

Ans. b.

Ans. c.

Ans. a.

Ans.

21 Revision Tour II
Ans.

Ans. a.

Ans. c. Scanner input

B. Fill in the blanks.


1. The break
2. The
nested loops.
4. The
if block.
6. The sqrt()
double.
8. The
comments are two types of comments in Java.
10. Any error in the grammar of the language is a error.

C. State whether the following statements are True (T) or False (F).
F
T
F
F
F
F
T
F
F
F

SECTION A
1.

Ans.
2.
Ans.
3.
Ans.
4.
Ans.

5.
Ans.

23 Revision Tour II
6.
Ans.
computer program.

7.

Ans.

8.
Ans.
9.
Ans.

10.
Ans.
11.
Ans.
12.
Ans.

13.
Ans.
14.
Ans.

before entering the loop.

15.

Ans.

loop.

16.

Ans.

statement;

17. Compare loops according to its usage.


Ans.

25 Revision Tour II
18.
Ans.

public class Loops

1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

19. Name two jump statements and their use.


Ans. Jump statements in Java:
break
statement in which it appears.

appears, begins.
20.
Ans.

21.
Ans. Similarity

of the loop.
22.

Ans.
23.
Ans.
24.

Ans.

lines.
25.
when

break;

27 Revision Tour II
Ans.

Wrong Input
ii. Wrong Input

26. Convert the following if else if construct into switch case

else

Ans.

case 1:

break;
case 2:

break;
case 3:

break;

27.

else

Ans.
28. Rewrite the following program segment using the if .. else statement.

Ans.

else
comm=0;
29.

else

Ans.

30. Convert the following segment into an equivalent do loop.

Ans.

c=c-2;

31.

int i;

Ans.
20

32.
int m = 5, n = 10;

n–;

29 Revision Tour II
Ans.
int m=5,n;

33. Convert following do-while loop into for loop.


int i = 1;

Ans.

34.
int m=2;
int n=15;

Ans.
m=3
n=14
35.

ii. Write the output of the program segment.


Ans.

WIN
WIN
36.

int k=1, i=2;

Ans.

60
37.

return y;
Ans.

38.

int p=200;

break;
p=p-20;

Ans.

80
39.
i. Division by a variable that contains a value of zero.

31 Revision Tour II
Ans.

ii. Logical error

40.

Ans.

2.0
3.0
41.
int ctr = 0;

Ans.
Final value of ctr is 15.
42.

Ans.
43.

Ans.
44. Rewrite the following program segment using if-else statements instead of the ternary
operator.

Ans.

else
45.

Ans.

46.

b = a – b;
a = a – b;

47.

break;

Ans.

48.

33 Revision Tour II
break;
else

Ans.
5
10

49.

Ans.
12

50.
Ans.

51.

Ans.

35 Revision Tour II
SECTION B
1.
Ans.
class Sol1

2.

Ans.
class Sol2

You might also like