Skip to content

Commit 045cc1f

Browse files
authored
Add files via upload
1 parent 4344c15 commit 045cc1f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Methods/Varargs.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Varargs {
2+
// A method that takes variable number of integer
3+
// arguments.
4+
static void varargs(int... x) {
5+
System.out.println("Number of arguments: " + x.length);
6+
7+
// using for each loop to display contents of x
8+
for (int i : x)
9+
System.out.print(i + " ");
10+
System.out.println();
11+
}
12+
13+
// Driver code
14+
public static void main(String args[]) {
15+
// Calling the varargs method with different number
16+
// of parameters
17+
varargs(100); // one parameter
18+
varargs(1, 2, 3, 4,10,20); // four parameters
19+
varargs(); // no parameter
20+
}
21+
}

0 commit comments

Comments
 (0)