0

java code error

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(n); int marks[] = new int[n]; for(int i = 0; i<n; i++) { marks[i] = sc.nextInt(); } int averagemarks = 0; for(int i = 0; i<n; i++) { averagemarks += marks[i]; } averagemarks /= n; System.out.println("the average marks are " + averagemarks); } }

4th Feb 2021, 9:33 AM
Arjun
Arjun - avatar
3 Respuestas
+ 5
Try to use `double` rather than `int` as type of <averagemarks>. Integer division doesn't support fractions.
4th Feb 2021, 9:39 AM
Ipang
+ 2
This code is error free. Just write double or float to get floating points
4th Feb 2021, 11:00 AM
Atul [Inactive]
0
Yes , right the problem is the type of averagemarks it should be either a double or a float
4th Feb 2021, 11:05 AM
Nassera
Nassera - avatar