-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvarArgs.java
More file actions
45 lines (43 loc) · 1.2 KB
/
varArgs.java
File metadata and controls
45 lines (43 loc) · 1.2 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
package src.arrays;
class varArgs {
static void vatest(String msg, int ... v) {
System.out.print(msg + v.length + "Contents: ");
for(int x: v) {
System.out.print(x + " ");
}
System.out.println();
}
public static void main(String[] args) {
vatest("arg1", 10);
vatest("arg2", 3, 2, 1);
vatest("arg3");
}
}
class overloadVarargs {
static void test(int ... v) {
System.out.print("Number of args: " + v.length + " Contents: ");
for(int x: v) {
System.out.print(x + " ");
}
System.out.println();
}
static void test(Boolean ... v) {
System.out.print("Number of args: " + v.length + " Contents: ");
for(boolean x: v) {
System.out.print(x + " ");
}
System.out.println();
}
static void test(String msg, int ... v) {
System.out.print(msg + v.length + " Contents: ");
for(int x: v) {
System.out.print(x + " ");
}
System.out.println();
}
public static void main(String[] args) {
test(4, 3, 0);
test(false, true, false, true);
test("Number of args: ", 83, 21);
}
}