-
Notifications
You must be signed in to change notification settings - Fork 0
/
Varargs.java
32 lines (29 loc) · 896 Bytes
/
Varargs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class Varargs {
// static int sum(int a,int b)
// {
// return a+b;
// }
// static int sum(int a,int b,int c)
// {
// return a+b+c;
// }
static int sum(int ...arr)
{
int result=0;
for(int a:arr)
{
result+=a;
}
return result;
}
public static void main(String[] args)
{
try (Scanner sc = new Scanner(System.in)) {
}
//System.out.println("Welocome");
System.out.println("The sum of a and b is:"+ sum(1,2));
System.out.println("The sum of a,b and c is:"+ sum(1,2,3));
System.out.println("The sum of a,b,c and d is:"+ sum(1,2,3,4));
}
}