‹ Back to the paper
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:
| TeacherA | TeacherB |
|---|---|
| `int average = (____)((m1+m2+m3)/3);` | `int average = Math.round((m1+m2+m3)/3);` |
Answer
Answer
AIint 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.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 39.