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 Print a pattern using Asterisks(*). The no. of rows will be taken from the user. In the first Row the no. of spaces will be (n-1) [Here, we considered that, the user entered n no. of rows as input],and then a *. In the 2nd Row the number of Spaces will be decreased and the no. of * will be increased by 1. In that way, the last Row(nth row) have no Spaces and have all(n) *.
----*
---**
--***
-****
*****
► Here, - sign is used as Space for better understanding.
---**
--***
-****
*****
input:
The no. of Rows.output:
The Pattern will be printed on the screen in the given range.CODE---->
#include<stdio.h>
int main()
{
int i,j,k,n;
printf(" Please, Enter the no. of Rows : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Download the C-Program file of this Program.
RESULT:
Comments
Post a Comment