You are viewing a single comment's thread. Return to all comments →
Passing as vararg need "," so sending sepratly each.
public class Solution { void adds(int ...a){ int sum=0; for(int i=0;i } } System.out.println("="+sum);
} public static void main(String[] args) { Scanner sc = new Scanner(System.in); Solution s =new Solution(); ArrayList<Integer> li = new ArrayList<>(); for(int i = 0 ; i<6 ; i++){ li.add(sc.nextInt()); } int[] arr = li.stream().mapToInt(Integer::intValue).toArray(); s.adds(arr[0], arr[1]); s.adds(arr[0], arr[1], arr[2]); s.adds(arr[0], arr[1], arr[2], arr[3], arr[4]); s.adds(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]); }
}
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 →
Passing as vararg need "," so sending sepratly each.
public class Solution { void adds(int ...a){ int sum=0; for(int i=0;i } } System.out.println("="+sum);
}