Advertisement
Aminpro

Variable Length Arguments

Dec 29th, 2013
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.26 KB | None | 0 0
  1. class apples{
  2.     public static void main(String args[]){
  3.         System.out.println(average(1,2,3,4,5,6,7,8,9));
  4.    
  5.        
  6.     }
  7.    
  8.     public static int average(int...numbers){
  9.         int total = 0;
  10.         for(int x:numbers)
  11.         total += x;
  12.        
  13.         return total/numbers.length;
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement