-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaximum.java
41 lines (39 loc) · 816 Bytes
/
maximum.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
//write a java program to input 5 elements of an array. calculate the average,maxmimm
//and minimum of the array and display the result
import java.util.Scanner;
class maximum
{
public static void main(String[] args)
{
Scanner ab=new Scanner(System.in);
int a[];
a=new int[5];
int min,max,sum=0,i;
double avg;
System.out.println("enter the element: ");
for(i=0;i<5;i++)
{
a[i]=ab.nextInt();
}
min=a[0];max=a[0];
for(i=0;i<5;i++)
{
if (a[i]<min)
{
min=a[i];
}
if(a[i]>max)
{
max=a[i];
}
}
for(i=0;i<5;i++)
{
sum=a[i]+sum;
}
avg=sum/5.0;
System.out.println("min: " + min);
System.out.println("max: " + max);
System.out.println("avg: " + avg);
}
}