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.
public void add(int... nums){
int sum = nums[0];
System.out.print(nums[0]);
for(int i = 1 ; i<nums.length-1;i++){
System.out.print("+"+nums[i]);
sum =sum+nums[i];
}
sum =sum+nums[nums.length-1];
System.out.print("+"+nums[nums.length-1]+"="+sum);
System.out.println();
}
}
Cookie support is required to access HackerRank
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{
}