Simple game in core java
it is simple and easy to learn. in this game person1 enter a number if it is odd number he will get 1 mark and then person 2 enter one number(p1 and p2 number add )after adding if it is qdd number he will get 1 mark like this it will repeat 25 time and finally display the winner name.import java.io.*;
public class Games {
public static void main(String a[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int p1 = 0,p2=0,e = 0;
for(int i=1;i<=25;i++)
{
System.out.println("Enter Number Person1 : ");
int b=Integer.parseInt(br.readLine());
int f=e+b;
System.out.println("person1 number add to person2 number: "+f);
if(f%2!=0)
{
p1++;
System.out.println("Person1 Score : "+p1);
}
System.out.println("Enter Number Person2 : ");
int c=Integer.parseInt(br.readLine());
int d=c+b;
System.out.println("person2 number add to person1 number: "+d);
if(d%2!=0)
{
p2++;
System.out.println("Person2 Score : "+p2);
}
e=d;
}
if(p2<p1)
{
System.out.println("Person1 won");
}
else if(p2>p1) {
System.out.println("Person2 won");
}
else{
System.out.println("Person1 and person2 equal");
}
}
}
No comments:
Post a Comment