Created
April 29, 2016 19:55
-
-
Save cobratbq/599eed66421ed9cfff3bb26c5d061b07 to your computer and use it in GitHub Desktop.
More flexible implementation of summing-method
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
public class Test { | |
public static void main(String[] args) { | |
final ArrayList<Double> list = new ArrayList<>(); | |
list.add(1.3); | |
list.add(1.4); | |
list.add(1.7); | |
list.add(2.3); | |
flexibleSum(list); | |
} | |
public static void flexibleSum(final Iterable<Double> values) { | |
double sum = 0; | |
for (final double d : values) { | |
sum += d; | |
} | |
System.out.println(Double.toString(sum)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment