Kattis Problem: Batter Up


Problem Link

https://open.kattis.com/problems/batterup

 

Sample Solution


import java.util.Scanner;
class BatterUp{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
float sum = 0, avg=0;
int[] num = new int[n];
for (int i=0; i<n; i++) {
num[i]=in.nextInt();
if (num[i]<0)
{
num[i]=0;
continue;
}
else{

sum=sum+num[i];
avg+=1;
}
}
System.out.println(sum/avg);
}
}

Sonam Dargay

Kuzu Zangpo la! I am Sonam Dargay, a student in the College of Science and Technology affiliated to The Royal University of Bhutan. I am a tech enthusiast student, studying Bachelor of Engineering in Information Technology.

You may also like...

%d bloggers like this: