Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cl.adl;
- import java.util.*;
- public class Ejemplo1 {
- public static void main(String[] args) {
- ArrayList<Integer> numerosAPromediar = new ArrayList<Integer>();
- for (int i=0; i<args.length; i++) {
- numerosAPromediar.add(Integer.parseInt(args[i]));
- }
- if (numerosAPromediar.size() > 0)
- System.out.println(promedio(numerosAPromediar));
- else
- System.out.println("No hay datos.");
- }
- public static Integer promedio(ArrayList<Integer> numeros) {
- int suma = 0;
- /*
- for (int i: numeros) {
- suma += i;
- }
- */
- for (Iterator iterator = numeros.iterator(); iterator.hasNext();) {
- suma = suma + (Integer)iterator.next();
- }
- Integer calculoPromedio = suma/numeros.size();
- return calculoPromedio;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement