# Sum of the maximum and the minimum element Program in java

## Question:

Anjali gets n numbers in an array. Write a Java program to print the sum of the maximum and the minimum element in the array. If the size of an array is 0 or less print “Invalid Array Size”.

Sample Input 1:

Enter the size of an array:

5

Enter the elements:

45

23

48

90

89

Sample Output 1:

113

Sample Input 2:

Enter the size of an array:

0
Sample Output 2:

Invalid Array Size

### CODE:–

```import java.util.*;
public class Sum
{
int max(int[] arr)
{
int max=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]>max)
{
max=arr[i];
}
}
return max;
}

int min(int[] arr)
{
int min=arr[0];
for(int i=0;i<arr.length;i++)
{
if(arr[i]<min)
{
min=arr[i];
}
}
return min;
}

public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
Sum obj=new Sum();

System.out.println("Enter the size of an array:");
int n=sc.nextInt();

if(n>0)
{
int[] arr=new int[n];

System.out.println("Enter the elements:");
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}

System.out.println(obj.max(arr)+obj.min(arr));
}
else
{
System.out.println("Invalid Array Size");
}

}
}```
```public class Student
{
private int id;
private String name;
private int[] marks;
private float average;

public void setId(int id)
{
this.id=id;
}

public int getId()
{
return this.id;
}

public void setName(String name)
{
this.name=name;
}

public String getName()
{
return this.name;
}

public void setMarks(int[] marks)
{
this.marks=marks;
}

public int[] getMarks()
{
return this.marks;
}

public void calculateAvg()
{   float sum=0;

for(int i=0;i<this.marks.length;i++)
{
sum+=this.marks[i];
}

average=(float)(sum/(this.marks.length));
setAverage(average);
}

{int flag=0;
for(int i=0;i<this.marks.length;i++)
{
if(this.marks[i]<50)
{
flag++;
}
}
if(flag>0)
{
}
else
{
if(this.average>=80 && this.average<=100)
{
}
else if(this.average>=50 && this.average<=79)
{
}
else
{
}
}

}

public void setAverage(float average)
{
this.average=average;
}

{
}

public float getAverage()
{
return this.average;
}