Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 39

1 mark

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)Short answerPrimitive values, Wrapper classes, Types and casting

Answer the following question.

Teachers of class XII are calculating the average attendance for 3 months. The class attendance for…

Teachers of class XII are calculating the average attendance for 3 months. The class attendance for 3 months is stored in double variables m1, m2, m3. TeacherA and TeacherB are using different techniques to get the average. Complete the code of TeacherA and name the technique used by him:
TeacherATeacherB
int average = (____)((m1+m2+m3)/3);int average = Math.round((m1+m2+m3)/3);

Answer

Answer

int average = (int)((m1+m2+m3)/3); TeacherA uses type casting (narrowing/explicit type conversion) - it truncates the decimal part, while TeacherB's Math.round() rounds off the value to the nearest integer.