Page 96 - TP_iPlus_V2.1_Class8
P. 96
3. The following questions consist of two statements – Assertion (A) and Reasoning (R).
Answer these questions by selecting the appropriate option given below:
Assertion (A): Conditional statements in Java allow you to execute different code blocks based
on specified conditions.
Reason (R): They enhance the flexibility and control of a Java program, providing branching
based on logical tests.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
Assertion (A): Looping statements in Java are used to execute a block of code repeatedly.
Reason (R): They help streamline repetitive tasks and keep code concise by iterating through a
specified range.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
#Coding & Computational Thinking
Higher Order Thinking Skills (HOTS)
1. Observe the given Java code and state what is it doing? Try and
execute the same.
public class magic {
public static void main(String[] args) {
int sum = 0;
int n = 1000;
for (int i = 1; i <= n; ++i) {
sum += i;
}
System.out.println("Sum = " + sum);
}
}
2. Rahit is asked to write a Java program for finding the perimeter of a rectangle.
public class peri {
public static void main(String[] args) {
int l = 50;
int w = 25;
int per =2*l+w
}
System.out.println("Perimeter of rectangle, with sides 50 and 25 cm is
= " + per + " cm");
}
}
He is getting answer as 125 cm instead of 150 cm. He has some error in his code. Cite the error, state its
type and explain it.
94
iPlus (Ver. 2.1)-VIII

