We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6bd53ed commit 57112e5Copy full SHA for 57112e5
Advanced/JavaVarags.java
@@ -0,0 +1,19 @@
1
+// Author: Atharv Damle
2
+// Create a function to accept variable arguments and calculate and print their sum.
3
+// Full Question: https://www.hackerrank.com/challenges/simple-addition-varargs/problem
4
+
5
+class Add {
6
+ // ...a signifies a variable argument function. It accepts a variable number of integers
7
+ // and converts them to an int array.
8
+ void add(int ...a)
9
+ {
10
+ int sum = 0;
11
+ for (int i = 0; i < a.length - 1; i++)
12
13
+ sum += a[i];
14
+ System.out.print(a[i] + "+");
15
+ }
16
+ sum += a[a.length - 1];
17
+ System.out.println(a[a.length - 1] + "=" + sum);
18
19
+}
0 commit comments