Created
August 12, 2018 14:26
-
-
Save dheysonalves/be487abcac5fc71af18fa9317db5088c to your computer and use it in GitHub Desktop.
java-varags-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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