We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Varargs - Simple Addition
Java Varargs - Simple Addition
Sort by
recency
|
286 Discussions
|
Please Login in order to post a comment
class Add{
}
import java.io.; import java.lang.reflect.; import java.util.; import java.text.; import java.math.; import java.util.regex.;
//Write your code here class Add{ public static void add(int ...n){ int result=0; for(Integer i:n){ result+=i; System.out.print(i); if(i==n[n.length-1]) { System.out.print("="); System.out.println(result); break;} System.out.print("+");
}
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); }}
class Add{ void add(int ...a){ int count =0; for(int i=0;i