Skip to main content

Get Even Numbers Using Java Stream API

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 ...

C-Program of XOR calculation(2 bit)



In this C program we will calculate the XOR function between two bits(i.e: 0 or 1) and print the result, in the screen. The two bits(i.e: 0 or 1) will be taken from the user.

Discussion:

The XOR gate (sometimes EOR gate, or EXOR gate and pronounced as Exclusive OR gate) is a digital logic gate that gives a true (1 or HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive or; that is, a true output results if one, and only one, of the inputs to the gate is true. If both inputs are false (0/LOW) or both are true, a false output results. XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "one or the other but not both".(from Wikipedia) For full article click here.

input:

The two bits(i.e. 0 or 1)

output:

The XOR of the bits will be printed on the screen.

CODE---->


#include<stdio.h>
#include<conio.h>
main()
{
   int bit1,bit2;
   printf("Enter the 1st bit : ");
   scanf("%d",&bit1);
   printf("\nPlease, Enter the 2nd bit : ");
   scanf("%d",&bit2);
   if(bit1==0||bit1==1&&bit2==0||bit2==1)
   {
     if(bit1==bit2)
     {
       printf("\n\nThe result is %d XOR %d = 0",bit1,bit2);
     }
     else
     {
       printf("\n\nThe result is %d XOR %d = 1",bit1,bit2);
     }
   }
   else
   {
     printf("\n\nSorry, You have entered wrong choice/value.");
   }
   getch();
}




Don't just read, write it, run it.....

RESULT:


Comments

Post a Comment