You are viewing a single comment's thread. Return to all 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); }}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Varargs - Simple Addition
You are viewing a single comment's thread. Return to all 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); }}