Java Varargs - Simple Addition

  • + 0 comments

    class Add{
    public void add(int... a){ int sum = 0; int plus = a.length-1; for(int x:a){ sum += x; System.out.print(x);
    if(plus>0){ System.out.print("+"); plus--; }
    } System.out.print("="+sum); System.out.println(); } }