Write a Java program using a method with varargs to calculate the total of long integers
public class LongTotalCalculator { static long calculateTotal(long... numbers) { if (numbers.length == 0) { throw new IllegalArgumentException("No numbers provided"); } long total = 0; for (long num : numbers) { total += num; } return total; } public static void main(String[] args) { long total = calculateTotal(1000000L, 2000000L, 3000000L); System.out.println("Total : " + total); } }
Total : 6000000
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions