JAVA 1.5 Find the highest mark and average mark secured by him "s" number of subjects.

Find the highest mark and average mark secured by him "s" number of subjects.

import java.util.Scanner;
public class Exercise{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double mark_avg;
 int result;
 int i;
 int s;
       s = input.nextInt();   
      int[] arr = new int[s];   
for(i=0;i<arr.length;i++)
  {
        arr[i]=input.nextInt();
  }

 result=arr[0];
int sum=0;
for(i=1;i<arr.length;i++)
{

  if(result<arr[i])
    result=arr[i];
}
for(i=0;i<arr.length;i++)
{
  sum=sum+arr[i];
}
mark_avg=sum/arr.length;
System.out.println(result);
System.out.print(mark_avg);
 }
}

Sample input and Output:
3
20 50 20
50
30

No comments:

Post a Comment