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 ...
The Dice Game
The download link is given below:
Download the C-Program file of this Game.
Rules :
1.Every Player gets 100$. 2. Every Player bet 10$ on a number. 3. Dice will be thrown. A random number will generate. 4. The closest bet number to the dice will win. 5.If both players bet the same number, no prize. Better Luck, Next time !! 6. If no money left, then you have lost. 7. The last Player with money, WINS !!! 8. In the Best of 3 match, two-player(s) will be fighting for only three rounds. The major winner of those three rounds will win. However, if both players win only 1 round or no round, then it will call a "Draw".
About :
Hello guys... Another C-program game is here. This is a product of - ProgramJoy.blogspot.com This is purely for entertainment and fun for new programmers or beginners. If any damage caused by this product: Any kind of damage (hardware or software related) by this product is unintentional and ProgramJoy is not responsible for this any kind of damage. The code is also available on our Blog/Website: https://programjoy.blogspot.com Follow us on Facebook: https://facebook.com/programjoyofficial Twitter: @ProgramJoy Email: programjoyofficial@gmail.com Please, subscribe and give a thumbs up, if you like the game.
CODE---->
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void str_gm();void rules();void about();void Exit();void delay(int);void menu();void PVP();void PVC();void BST3();
void str_gm()
{
int c;
while(1)
{
system("cls");
printf("\n1.Player Vs. Player\n2.Player Vs. Computer\n3.Best of 3(Player Vs Player)\n4.Main Menu\n");
printf("Your Choice: ");
scanf("%d",&c);
printf("\n\n");
switch(c)
{
case 1: PVP();
break;
case 2: PVC();
break;
case 3: BST3();
break;
case 4: system("cls");
menu();
break;
default: printf("\nInvalid Choice. Try again.");
break;
}
}
}
void PVP()
{
int p1,p2,m1=100,m2=100,x;
int rand_num,dif1,dif2;
while(1)
{
system("cls");
printf("\n\n\"Player 1\", Choose a number between (1-10): ");
scanf("%d",&p1);
while(1)
{
if(p1>=1&&p1<=10)
break;
else
{
printf("\n\"Player 1\", please, choose a number between(1-10): ");
scanf("%d",&p1);
}
}
printf("\n\n\"Player 2\", Choose a number between (1-10): ");
scanf("%d",&p2);
while(1)
{
if(p2>=1&&p2<=10)
break;
else
{
printf("\n\"Player 2\", please, choose a number between(1-10): ");
scanf("%d",&p2);
}
}
rand_num=rand()%10;
printf("\nThe dice says...");
delay(3000);
printf("\n\t%d\n",rand_num);
dif1=rand_num-p1;
dif2=rand_num-p2;
if(dif1<0)
dif1=dif1*(-1);
if(dif2<0)
dif2=dif2*(-1);
if(dif1<dif2)
{
m1=m1+10;
m2=m2-10;
printf("\n\"Player 1\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Player 2 has %d$ money.\"",m2);
}
else if(dif1==dif2)
{
m1=m1+0;
m2=m2+0;
printf("\n\"No Player\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Player 2 has %d$ money.\"",m2);
}
else
{
m1=m1-10;
m2=m2+10;
printf("\n\"Player 2\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Player 2 has %d$ money.\"",m2);
}
delay(2000);
printf("\n\n\nNow, Press 1 to continue and press 0 to for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
else
{
while(x!=1)
{
printf("\npress 1 to continue and press 0 for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
}
}
if(m2==0)
{
printf("\n\nHoorah !!! Player 1 Won !!!");
delay(8000);
break;
}
if(m1==0)
{
printf("\n\nHoorah !!! Player 2 Won !!!");
delay(8000);
break;
}
}
}
void PVC()
{
int p1,p2,m1=100,m2=100,x; //p2 is computer.
int rand_num,rand_comp,dif1,dif2;
while(1)
{
system("cls");
printf("\n\n\"Player 1\", Choose a number between (1-10): ");
scanf("%d",&p1);
while(1)
{
if(p1>=1&&p1<=10)
break;
else
{
printf("\n\"Player 1\", please, choose a number between(1-10): ");
scanf("%d",&p1);
}
}
printf("\n\n\"Computer\", Choosing a number between (1-10): ");
rand_comp=rand()%10;
delay(2000);
printf("%d",rand_comp);
p2=rand_comp;
rand_num=rand()%10;
printf("\nThe dice says...");
delay(3000);
printf("\n\t%d\n",rand_num);
dif1=rand_num-p1;
dif2=rand_num-p2;
if(dif1<0)
dif1=dif1*(-1);
if(dif2<0)
dif2=dif2*(-1);
if(dif1<dif2)
{
m1=m1+10;
m2=m2-10;
printf("\n\"Player 1\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Computer has %d$ money.\"",m2);
}
else if(dif1==dif2)
{
m1=m1+0;
m2=m2+0;
printf("\n\"No one\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Computer has %d$ money.\"",m2);
}
else
{
m1=m1-10;
m2=m2+10;
printf("\n\"Computer\" has won this round. \n");
printf("\nSo, \"Player 1 has %d$ money.\"",m1);
printf("\nSo, \"Computer has %d$ money.\"",m2);
}
delay(2000);
printf("\n\n\nNow, Press 1 to continue and press 0 for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
else
{
while(x!=1)
{
printf("\npress 1 to continue and press 0 for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
}
}
if(m2==0)
{
printf("\n\nHoorah !!! Player 1 Won !!!");
delay(8000);
break;
}
if(m1==0)
{
printf("\n\nHoorah !!! Computer Won !!!");
delay(8000);
break;
}
}
}
void BST3()
{
int p1,p2,x,p1m=0,p2m=0,c=1;
int rand_num,dif1,dif2;
while(c<=3)
{
system("cls");
printf("\n\n\"Player 1\", Choose a number between (1-10): ");
scanf("%d",&p1);
while(1)
{
if(p1>=1&&p1<=10)
break;
else
{
printf("\n\"Player 1\", please, choose a number between(1-10): ");
scanf("%d",&p1);
}
}
printf("\n\n\"Player 2\", Choose a number between (1-10): ");
scanf("%d",&p2);
while(1)
{
if(p2>=1&&p2<=10)
break;
else
{
printf("\n\"Player 2\", please, choose a number between(1-10): ");
scanf("%d",&p2);
}
}
rand_num=rand()%10;
printf("\nThe dice says...");
delay(3000);
printf("\n\t%d\n",rand_num);
dif1=rand_num-p1;
dif2=rand_num-p2;
if(dif1<0)
dif1=dif1*(-1);
if(dif2<0)
dif2=dif2*(-1);
if(dif1<dif2)
{
printf("\n\"Player 1\" has won this round. \n");
p1m++;
c++;
printf("\nScore Board:\t Player 1: %d\t Player 2: %d",p1m,p2m);
}
else if(dif1==dif2)
{
printf("\n\"No Player\" has won this round. \n");
c++;
printf("\nScore Board:\t Player 1: %d\t Player 2: %d",p1m,p2m);
}
else
{
printf("\n\"Player 2\" has won this round. \n");
p2m++;
c++;
printf("\nScore Board:\t Player 1: %d\t Player 2: %d",p1m,p2m);
}
delay(2000);
printf("\n\n\nNow, Press 1 to continue and press 0 to for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
else
{
while(x!=1)
{
printf("\npress 1 to continue and press 0 for main menu(do not enter other value): ");
scanf("%d",&x);
if(x==1)
system("cls");
else if(x==0)
{
system("cls");
menu();
break;
}
}
}
}
if(p1m>p2m)
{
printf("\n\nHoorah !!! Player 1 Won !!!");
delay(8000);
}
if(p1m==p2m)
{
printf("\n\nAww Snap !!! Match Draw !!!");
delay(8000);
}
if(p1m<p2m)
{
printf("\nHoorah !!! \"Player 2\" has won");
delay(8000);
}
}
void rules()
{
int x;
printf("\n\n\n## Rules ##\n\n\n1.Every Player gets 100$.\n\n2.Every Player bet 10$ on a number.\n\n3.Dice will be thrown. A random number will generate.\n\n4.The closest bet number to the dice will win.\n\n5.If both player bets the same number, no prize. Better Luck, Next time !!\n\n6.If no money left, then you have lost.\n\n7.The last Player with money, WINS !!!\n\n8.In the Best of 3 match, two player(s) will be fighting for only three rounds. The major winner of those three rounds will win. However, if both player(s) win only 1 round or no round, then it will call a \"Draw\"");
delay(3000);
printf("\n\n\nPress 1, to back to Main Menu. Do not enter other value: ");
scanf("%d",&x);
if(x==1)
system("cls");
else
{
while(x!=1)
{
printf("\npress 1 to back, do not enter other value: ");
scanf("%d",&x);
if(x==1)
system("cls");
}
}
}
void about()
{
int x;
printf("\n\n\n## About ##\n\n\nHello guys...\nAnother C-program game is here.\n\nThis is a product of - ProgramJoy.blogspot.com\n\nThis is purely for entertainment and fun for new programmers or beginners.\n\nIf any damage caused by this product: Any kind of damage (hardware or software related) by this product is unintentional and ProgramJoy is not responsible for this any kind of damage.\n\nThe code is also available on our Blog/Website: https://programjoy.blogspot.com\n\nFollow us on Facebook: https://facebook.com/programjoyofficial\n\nTwitter: @ProgramJoy\n\nEmail: programjoyofficial@gmail.com\n\nPlease, Subscribe and give a thumbs up, if you like the game.");
delay(3000);
printf("\n\n\nPress 1, to back to Main Menu. Do not enter other value: ");
scanf("%d",&x);
if(x==1)
system("cls");
else
{
while(x!=1)
{
printf("\npress 1 to back, do not enter other value: ");
scanf("%d",&x);
if(x==1)
system("cls");
}
}
}
void Exit()
{
exit(0);
}
void delay(int milli_sec)
{
// Stroing start time
clock_t start_time=clock();
// looping till required time is not acheived
while(clock()<start_time+milli_sec);
}
void menu()
{
int choice;
while(1)
{
printf("\n\n### Main Menu ###\n\n1.Start Game\n2.Rules\n3.About\n4.Exit");
printf("\n\nEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: system("cls");
str_gm();
break;
case 2: system("cls");
rules();
break;
case 3: system("cls");
about();
break;
case 4: system("cls");
Exit();
break;
default: printf("\nWrong Choice. Try Again.");
delay(2000);
system("cls");
menu();
break;
}
}
}
int main()
{
menu();
return 0;
}
Comments
Post a Comment