Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active December 12, 2021 17:41
Show Gist options
  • Save sunmeat/5ac81b5797ad3b0cde49 to your computer and use it in GitHub Desktop.
Save sunmeat/5ac81b5797ad3b0cde49 to your computer and use it in GitHub Desktop.
var args
package com.alex.methods;
class VarArgs {
public static void sum(int[] ar) {
int s = 0;
for (int current : ar) {
s += current;
}
System.out.println(s);
}
public static void summa(int... args) {
int s = 0;
for (int current : args) {
s += current;
}
System.out.println(s);
}
public static void main(String[] args) {
sum(new int[]{1, 2, 3, 4, 5});
summa(1, 2, 3, 4, 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment