source: doc/theses/rob_schluntz/examples/intro/variadic.java @ ff39851

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 ff39851 was 728df66, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

more documentation name changes

  • Property mode set to 100644
File size: 508 bytes
RevLine 
[9c14ae9]1class 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.