Java Stream API — Even Numbers (Full Screen) Java Stream API — Get Even Numbers Example 1 — Filter even numbers from a list Creates a list, uses Stream to filter evens, and prints them. Copy import java.util.*; import java.util.stream.*; public class EvenNumbersStream { public static void main(String[] args) { // Create a list of numbers List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // Use Stream API to filter even numbers List<Integer> evenNumbers = numbers.stream() .filter(n -> n % 2 == 0) .collect(Collectors.toList()); // Print the even numbers System.out.println( "Even numbers: " + evenNumbers); } } Example 2 — Use IntStream.rangeClosed ...
In this C-program we will scan the numbers using array and then we will calculate the sum of the given numbers, also using array. The numbers will be taken from the user.
input:
5 numbers.(i.e : 5,6,9,56,548)output:
The sum of the given numbers will be printed on the screen.
CODE---->
#include<stdio.h>
#include<stdlib.h>
main()
{
int arr[5],i,sum=0;
printf(" Enter Five numbers : ");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
sum=sum+arr[i];
}
printf("\n The sum of the given 5 numbers is : %d\n",sum);
system("pause");
}
RESULT:
Adobe Express
ReplyDeleteFortnite
Nice Work >>> https://cracksoftsfree.com/download-button/
ReplyDeleteHi Whts Up >>>>>> https://crackstudio.info/direct-setup/
ReplyDelete