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); } }
3 Antworten
+ 5
Try to use `double` rather than `int` as type of <averagemarks>. Integer division doesn't support fractions.
+ 2
This code is error free. Just write double or float to get floating points
0
Yes , right the problem is the type of averagemarks it should be either a double or a float