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 perform operations over Stack(i.e: Push Operation, Pop Operation and Display Operation). The Choice(i.e: Push,Pop or Display) will be made by the user and The Number will be taken from the user(i.e: For Push Operation).
input:
The Choice(i.e Push, Pop or Display) & The Number (integers) (i.e. for Push Operations) (15,10,128 etc.)output:
The Operations will be excecuted as choosen by the user.
CODE---->
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10
int s[MAXSIZE],top=-1;
void push(int x)
{
if(top==MAXSIZE-1)
printf("\n Stack Overflow.");
else
{
top++;
s[top]=x;
}
}
void pop()
{
int temp;
if(top==-1)
printf("\n Stack Underflow.");
else
{
temp=s[top];
printf("\n %d is Popped from Stack.",temp);
top--;
}
}
void display()
{
int i;
printf("\n The Stack Elements are...\n");
if(top==-1)
{
printf("\n No Elements to display.");
}
else
{
for(i=top;i>=0;i--)
printf(" %d ",s[i]);
}
}
int main()
{
int choice,x;
while(1)
{
printf("\n1. Push\n2. Pop\n3. Display\n4. Exit");
printf("\n Please, Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 : printf("\n Enter Element : ");
scanf("%d",&x);
push(x);
break;
case 2 : pop();
break;
case 3 : display();
break;
case 4 : exit(0);
default : printf("\n Wrong Choice.");
}
}
}
RESULT:
Comments
Post a Comment