-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram5.java
More file actions
62 lines (37 loc) · 1.12 KB
/
Copy pathProgram5.java
File metadata and controls
62 lines (37 loc) · 1.12 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//WAP to create a class Student having fields name, rollno, marks in 5 subjects.
//The class should contain 2 functions void accept and void display_result which
//displays the average marks.
import java.util.*;
class Student{
public String name;
public long rollno;
public int marks[]=new int[5];
public void accept(){
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
name = sc.nextLine();
System.out.print("Enter your roll no.: ");
rollno = sc.nextLong();
for(int i=0; i<5; i++){
System.out.print("Enter the marks in 5 subjects: ");
marks[i] = sc.nextInt();
}
}
public display_result(){
int sum=0;
for(i=0; i<marks.length; i++){
sum+=marks[i];
}
return (sum/5);
}
}
public class Program5{
public static void main(String args[]){
Student Ap = new Student();
Ap.accept();
double input2 = Ap.display_result();
System.out.println("Name of Student: "+Ap.name);
System.out.println("Roll number of Student: "+Ap.rollno);
System.out.println("Average Marks of Student: "+Ap.input2);
}
}