Skip to main content

Posts

Showing posts from March, 2019

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

A Pattern using Asterisk(*) in C-Language

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(n th 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 ( ...

Inverted Half-Pyramid using Asterisk(*) in C-Language

In this C -program we will Print the inverted "Half-Pyramid" using Asterisks(*). The no. of rows will be taken from the user. ***** **** *** ** * input: The number of the rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> int main () { int i , j , n ; printf ( " Please, Enter the no. of Rows : " ); scanf ( "%d" ,& n ); if ( n <= 0 ) { printf ( "\n Please, Enter a Positive number." ); printf ( "\n Wrong Input." ); exit ( 0 ); } for ( i = n ; i >= 1 ; i --) { for ( j = i ; j >= 1 ; j --) { printf ( "*" ); } printf ( "\n" ); } return 0 ; } Download the C-Program file of this Program. Don't just read, write it, run it..... RESULT :

Half Pyramid Using ABC (alphabets) in C-language

In this C -program we will Print the "Half-Pyramid" using Alphabet(A,B,C). The range will be taken from the user. A AB ABC ABCD ABCDE input: The Range(a letter). The input letter must be in Capital, as we created this C-Program for Capital letters. output: The Pattern will be printed on the screen in the given range. CODE----> //Half-Pyramid using Alphabets #include<stdio.h> int main () { int j = 0 ; char alphabet = 'A' , i = 'A' , n ; printf ( " Please, Enter a Capital Letter (no small Letter) : " ); scanf ( "%c" ,& n ); while ( i <= 'Z' ) //checking, entered letter is capital. { if ( i == n ) { j = 1 ; break ; } else i ++; } if ( j == 0 ) { printf ( "\n Wrong input Entered." ); exit ( 0 ); } //Checking Ends here. for ( i = 'A' ; i <= n ; i ++) ...