-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise1_5_R.java
More file actions
37 lines (35 loc) · 976 Bytes
/
Exercise1_5_R.java
File metadata and controls
37 lines (35 loc) · 976 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
34
35
36
37
import java.util.Scanner;
public class Exercise1_5{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double mark_avg;
int result;
int i;
int s;
//define size of array
s = input.nextInt();
//The array is defined "arr" and inserted marks into it of integer type.
int[] arr = new int[s];
for(i=0;i<arr.length;i++)
{
arr[i]=input.nextInt();
}
//initialise maximum element as first element of array.
int max=arr[0];
double sum=arr[0];
//traverse array elements to get the current max
for(i=1;i<arr.length;i++)
{
sum=sum+arr[i];
if(arr[i]>max)
max =arr[i];
}
//Store the highest mark in the variable max
//Store average mark in avgMarks
result=max;
mark_avg=sum/(arr.length);
//Evaluation code
System.out.println(result);
System.out.println(mark_avg);
}
}