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
|
294 Discussions
|
Please Login in order to post a comment
class Add { public void add(int... x) { //int r = 0; String seperator = ""; int count = 0; int result = 0; for(int a : x) { //System.out.println(count+a); count = count + a; //System.out.println(a); System.out.print(seperator +a); seperator = "+";
} }
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(); } }
class Add{
}