Last active
August 6, 2024 07:11
-
-
Save sunmeat/5ac81b5797ad3b0cde49 to your computer and use it in GitHub Desktop.
var args
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
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