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 calculate the summation of two numbers(int) using "Function" and print the result, in the screen. The two numbers will be taken from the user.
input:
Two numbers(int). (i.e. 15,23 etc.)output:
Summation of the given numbers(int) will be printed on the screen.
CODE---->
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int sum(); /* function declaration */
main() /* main function */
{
int choice;
printf("**********WELCOME**********\n\n");
printf("Please, select your choice.\n");
printf("1.Addition(press 1, for addition)\n2.Exit(press 2,for quit)\n\n");
printf("Please, Enter your choice : ");
scanf("%d",&choice);
if(choice==1)
sum(); /* function call */
if(choice==2)
exit(0);
getch();
} /* end of main() function */
/* function structure */
sum(){
int num1,num2,result;
printf("\nYou have selected addition option.\nPlease, Enter the 1st number : ");
scanf("%d",&num1);
printf("\nPlease, Enter the second number : ");
scanf("%d",&num2);
result=num1+num2;
printf("\nThe result is : %d + %d = %d",num1,num2,result);
}
RESULT:
Comments
Post a Comment