Skip to main content

Posts

Showing posts with the label Java Varargs - Simple Addition Hackerrank Solution

Java Varargs - Simple Addition Hackerrank Solution

 Java Varargs - Simple Addition Hackerrank Solution For Explanation Watch Video: Sample Input 1 2 3 4 5 6 Sample Output 1+2=3 1+2+3=6 1+2+3+4+5=15 1+2+3+4+5+6=21 Code: import  java.io.*; import  java.lang.reflect.*; import  java.util.*; import  java.text.*; import  java.math.*; import  java.util.regex.*; class Add{     public static void add(int... arr){         int sum = 0;         for(int i=0;i<arr.length-1;i++){             System.out.print(arr[i]+"+");             sum += arr[i];         }         sum += arr[arr.length-1];         System.out.print(a...