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 represent a Matrix. The elements or data will be taken from the user. First we input row 1 from left to right then the next row (row 2) and then the next row and so on. Well, in this case we representing a 3 X 3 Matrix, so here is only three rows.
input:
The elements of the Matrix.output:
The formed Matrix.
CODE---->
#include<stdio.h>
int main()
{
int arr_data[3][3],i,j=0,k=1;
for(i=0;i<3;i++)
{
printf("For Row %d\n",k);
for(j=0;j<3;j++)
{
printf("Enter data: ");
scanf("%d",&arr_data[i][j]);
}
k++;
}
printf("\nNow the Matrix is: \n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(" %d ",arr_data[i][j]);
printf("\n");
}
return 0;
}
Download the C-Program file of this Program.
RESULT :
For Row 1 Enter data: 10 Enter data: 20 Enter data: 30 For Row 2 Enter data: 40 Enter data: 50 Enter data: 60 For Row 3 Enter data: 70 Enter data: 80 Enter data: 90 Now the Matrix is: 10 20 30 40 50 60 70 80 90 -------------------------------- Process exited after 18.82 seconds with return value 0 Press any key to continue . . .
Images for better understanding :
Comments
Post a Comment