Java Varargs - Simple Addition

  • + 0 comments

    class Add { void add(int... numbers) { int sum = 0; StringJoiner sj = new StringJoiner("+"); for(int number: numbers) { sum+=number; sj.add(String.valueOf(number)); } System.out.println(sj.toString() + "=" + sum); }}