Advertisement
Eco

avg Array

Eco
Jul 1st, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.32 KB | None | 0 0
  1.     public static void varLength(){
  2.         System.out.println(avg(25,75,100));
  3.    
  4.     }
  5.  
  6.     public static int avg(int...num) { // ...  can put any amount of numbers in num
  7.         int total=0;
  8.     //  (x : num) all of the values in the array num are put in x one at a time.
  9.         for(int x:num)
  10.             total+=x;
  11.        
  12.         return total/num.length;
  13.    
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement