Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Learn VARARGS in 6 minutes! 💬

21.5K views on YouTube

#java #javatutorial #javacourse

public class Main {
public static void main(String[] args){

// varargs = allow a method to accept a varying # of arguments
// makes methods more flexible, no need for overloaded methods
// java will pack the arguments into an array
// … (ellipsis)

System.out.println(average(1, 2, 3, 4));

}
static double average(double… numbers){

double sum = 0;

if(numbers.length == 0){
return 0;
}

for(double number : numbers){
sum += number;
}

return sum / numbers.length;
}
}