You are viewing a single comment's thread. Return to all comments →
class Add{
public void add(int... arr){ int sum = arr[0]; System.out.print(arr[0]); for(int i=1;i<arr.length-1;i++){ System.out.print("+"+(arr[i])); sum=sum+arr[i]; } sum=sum+arr[arr.length-1]; System.out.print("+"+arr[arr.length-1]+"="+sum); System.out.println(); }
}
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{
}