Skip to content

Instantly share code, notes, and snippets.

@dheysonalves
Created August 12, 2018 14:26
Show Gist options
  • Save dheysonalves/be487abcac5fc71af18fa9317db5088c to your computer and use it in GitHub Desktop.
Save dheysonalves/be487abcac5fc71af18fa9317db5088c to your computer and use it in GitHub Desktop.
java-varags-example
public class Varags {
static int soma(int a,int b) {
return a + b;
}
static int soma(int a, int b, int c) {
return a + b + c;
}
static int soma(Integer ... vetor ) { //lista de argumentos de tamanho variável
int total = 0;
for (int i = 0; i < vetor.length; i++) {
total += vetor[i];
}
return total;
}
public static void main(String[] args) {
System.out.println(Varags.soma(2,3,4));
System.out.println(Varags.soma(1,2,3,4,5,6,7,8,9));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment