Last active
March 11, 2016 12:08
-
-
Save alexejVasko/d3da35aadaaa0e5f14c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package forEach; | |
public class AverAge { | |
public static void main(String[] args) { | |
int[] data = {1,2,3,4}; | |
System.out.println(average(data)); | |
int[] data2 = null; | |
System.out.println(average(data2)); | |
System.out.println(average(new int[0])); | |
System.out.println(average(new int[]{-1,-10,-1,-1})); | |
} | |
private static double average(int[] data){ | |
double sum = 0; | |
if(data == null || data.length == 0){ | |
System.out.print("heh"); | |
return -1; | |
} | |
for(int i: data){ | |
sum+=i; | |
} | |
sum = sum/data.length; | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment