You are viewing a single comment's thread. Return to all comments →
This can be a concise way of solving it without code repetition.
class Add { void add(int ...num){ System.out.print(num[0]); print(Arrays.copyOfRange(num, 1, num.length)); System.out.printf("=%d\n", IntStream.of(num).sum()); } void print(int ...num){ IntStream.of(num).forEach(i -> System.out.printf("+%d", i)); } }
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 →
This can be a concise way of solving it without code repetition.