import java.util.ArrayList;
/**
时 代 J a v a 公 众 号 - nowjava.com 提供
**/
public class Main
{
public static void main(String[] args)
{
Number[] numbers = {1, 2.4, 3, 4.1}; // Integers and Doubles
ArrayList<Number> numberList = new ArrayList<>();
for (Number element : numbers)
numberList.add(element); // place each number in numberList
System.out.printf("numberList contains: %s%n", numberList);
System.out.printf("Total of the elements in numberList: %.1f%n",
sum(numberList));
}
// calculate total of ArrayList elements
public static double sum(ArrayList<Number> list)
{
double total = 0; // initialize total
/**
* n o w j a v a . c o m - 时 代 Java 提 供
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。