Page 150 - ComputerScience_Class_11
P. 150
}
// Output of the program
Sum: 15
Difference: 5
Product: 50
Quotient: 2
10. What is the difference between Static and Dynamic initialisation?
Ans. The difference between them is as follows:
Static initialisation Dynamic initialisation
When a constant is directly assigned to a variable, it is known When a variable is initialised during the execution/run time of
as Static Initialisation. the program, then it is known as Dynamic Initialisation.
For example: For example:
int a=6;
int a=5, b=6, c; c=a+b;
String n="Name";
System.out.println(c);
D. Higher Order Thinking Skills (HOTS)
1. You are designing a banking application in Java where the bank wants to store account balances of its customers. However, some
of the balances need to be stored as float and others as double based on their range. Explain why using a float type for high-value
transactions (above ₹1,00,000) would lead to inaccuracies. How would you resolve this issue and ensure precise calculations for
all balances?
Ans. The float data type is a 32-bit single-precision floating-point type, which can result in precision loss for large numbers, especially
when dealing with high-value transactions. This is because float cannot accurately store values with many decimal places. To
ensure precise calculations for all balances, double should be used, as it is a 64-bit double-precision type. This provides higher
accuracy and avoids rounding errors, ensuring accurate calculations for balances, even for high-value transactions.
2. In a temperature monitoring system, temperature data is collected using different sensors that provide readings in Celsius (as
integers) and Fahrenheit (as floats). If you need to calculate the average temperature over a week, explain how mixed arithmetic
expressions might be used and why it's important to handle data types correctly to avoid errors in the final result.
Ans. When calculating the average temperature with mixed data types (integer for Celsius and float for Fahrenheit), Java automatically
promotes the integer to a floating-point type for the calculation, ensuring the decimal precision is maintained. However, if not
handled correctly, precision errors could occur, particularly if the calculation results in truncation. To avoid errors, it’s advisable to
convert both the Celsius and Fahrenheit readings to double before performing the calculation, ensuring that all values are treated
with the same precision and yielding accurate results.
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. Assertion (A): Arithmetic operators can only be used with primitive data types.
Reason (R): Arithmetic operators are designed to perform mathematical operations on variables that hold primitive values like int,
float and double.
Ans. d. A is false but R is true.
2. Assertion (A): Floating-point literals can only be positive numbers.
Reason (R): Floating-point literals represent real numbers and can have both positive and negative values.
Ans. d. A is false but R is true.
148 Touchpad Computer Science (Ver. 3.0)-XI

