forked from Shreerang4/learning-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarks.java
More file actions
34 lines (28 loc) · 804 Bytes
/
marks.java
File metadata and controls
34 lines (28 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
class Student {
private String name;
private int[] marks;
public Student(String name, int[] marks) {
this.name = name;
this.marks = marks;
}
public double getAverageMarks() {
int sum = 0;
for (int mark : marks) {
sum += mark;
}
return (double) sum / marks.length;
}
public void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Marks: " + Arrays.toString(marks));
System.out.println("Average marks: " + getAverageMarks());
}
}
public class marks {
public static void main(String args[]){
int[] marks = {80, 75, 85, 90, 95};
Student student = new Student("John Doe", marks);
student.displayDetails();
}
}