Answers for "Somme des éléments d'un tableau java"

0

Somme des éléments d'un tableau java

int[] nb = {1,2,3,4,5,6,7,8,9};
int somme = java.util.stream.IntStream.of(nb).sum();
System.out.println(somme); //45
Posted by: Guest on April-19-2022
0

Somme des éléments d'un tableau java

import java.util.*;
public class CompareTableaux
{
	public static void main(String[] args)
	{
		String[]
			arr1 = { "2", "3", "5", "7", "11" },
			arr2 = { "2", "4", "6", "8", "11", "12" };

		List<String> l1 = Arrays.asList(arr1);
		List<String> l2 = Arrays.asList(arr2);

		HashSet<String> communs = new HashSet<String>(l1);
		communs.retainAll(l2);

		HashSet<String> non_communs = new HashSet<String>(l1);
		non_communs.addAll(l2);
		non_communs.removeAll(communs);

		System.out.println(communs);      // [11, 2]
		System.out.println(non_communs);  // [12, 3, 4, 5, 6, 7, 8]
	}
}
Posted by: Guest on April-20-2022

Code answers related to "Somme des éléments d'un tableau java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language