Advertisement
thenewboston

Java Programming Tutorial - 35 - Variable Length Arguments

Aug 22nd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.29 KB | None | 0 0
  1. public class apples {
  2.    public static void main(String[] args) {
  3.       System.out.println(average(43,56,76,8,65,76,2,31));
  4.    }
  5.  
  6.    public static int average(int...numbers){
  7.       int total=0;
  8.       for(int x:numbers)
  9.          total+=x;
  10.      
  11.       return total/numbers.length;
  12.    }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement