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 Swap Two numbers using Bitwise Operators and then we will print the result on the screen. The Numbers will be taken from the user.
input:
The Numbers (integers) (i.e. 5,45,75 etc.)output:
After Swapping the Numbers will be printed on the screen.
CODE---->
#include<stdio.h>
#include<conio.h>
int main()
{
//swap two numbers using bitwise operator
int x,y;
printf(" Please, Enter the 1st Number : ");
scanf("%d",&x);
printf("\n Please, Enter the 2nd Number : ");
scanf("%d",&y);
//swapping -------->>
x=x^y;
y=x^y;
x=x^y;
printf("\n Now, the Numbers are : %d and %d",x,y);
return 0;
}
RESULT:
If the program is not running, you can remove the second line from the code(i.e: #include<conio.h> )
Comments
Post a Comment