ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 930f69e was
9c14ae9,
checked in by Rob Schluntz <rschlunt@…>, 8 years ago
|
add thesis source
|
-
Property mode set to
100644
|
File size:
508 bytes
|
Rev | Line | |
---|
[9c14ae9] | 1 | class variadic { |
---|
| 2 | int sum(int... args) { |
---|
| 3 | int s = 0; |
---|
| 4 | for (int x : args) { |
---|
| 5 | s += x; |
---|
| 6 | } |
---|
| 7 | print(args.length, " ", args[0], " ", args[args.length-1], "\n"); |
---|
| 8 | return s; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | void print(Object... objs) { |
---|
| 12 | for (Object obj : objs) { |
---|
| 13 | System.out.print(obj); |
---|
| 14 | } |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | public void run() { |
---|
| 18 | print("The sum from 1 to 10 is ", sum(1,2,3,4,5,6,7,8,9,10), ".\n"); |
---|
| 19 | print(sum(new int[]{1, 2,3}), "\n"); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public static void main(String args[]) { |
---|
| 23 | new variadic().run(); |
---|
| 24 | } |
---|
| 25 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.