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
|
297 Discussions
|
Please Login in order to post a comment
class Add{ public void add(int n1,int n2){ System.out.println(n1+ "+" +n2+ "=" +(n1+n2)); } public void add(int n1,int n2,int n3){ System.out.println(n1+ "+" +n2+ "+" +n3+ "=" +(n1+n2+n3)); } public void add(int n1,int n2,int n3,int n4){ System.out.println(n1+ "+" +n2+ "+" +n3+ "+" +n4+ "=" +(n1+n2+n3+n4)); } public void add(int n1,int n2,int n3,int n4,int n5){ System.out.println(n1+ "+" +n2+ "+" +n3+ "+" +n4+ "+" +n5+ "=" +(n1+n2+n3+n4+n5)); } public void add(int n1,int n2,int n3,int n4,int n5,int n6){ System.out.println(n1+ "+" +n2+"+" +n3+ "+" +n4+ "+" +n5+"+"+n6+ "=" +(n1+n2+n3+n4+n5+n6)); } }
class Add { void add(int... number) {
}
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(); } }