-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentVarArgs.java
54 lines (42 loc) · 993 Bytes
/
StudentVarArgs.java
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
class StudentVarArgs
{
public void display(String name, int...m){ //variable argument constructor
System.out.println("Name of student: "+name );
int sum = 0;
for(int w : m) { //enhanced for loops
sum = sum + w;
}
int p = sum/m.length;
System.out.println("Percentage: "+p);
if(p >= 90)
{
System.out.println("Grade A\n");
}
else if(p >= 80)
{
System.out.println("Grade B\n");
}
else if(p >= 70)
{
System.out.println("Grade C\n");
}
else if(p >= 60)
{
System.out.println("Grade D\n");
}
else if(p >= 40)
{
System.out.println("Grade E\n");
}
else
{
System.out.println("Grade F\n");
}
}
public static void main(String[] args)
{
StudentVarArgs a = new StudentVarArgs();
a.display("Sam", 60,70,80);
a.display("John", 60,70,80,90,100);
}
}