PRASHNIKAप्रश्निका
‹ Back to the paper

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

Computer Science20251 markShort answer
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

AI
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.
Primitive values, Wrapper classes, Types and casting

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 39.