-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameAdv.java
More file actions
66 lines (63 loc) · 1.48 KB
/
GameAdv.java
File metadata and controls
66 lines (63 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.botcoder;
import java.util.Scanner;
import java.lang.Math;
public class GameAdv
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("this is a game of rock paper scissor");
System.out.println("enter\n1 for rock\n2 for paper\n3 for scissor");
int a = 0;
int b = 0;
for(int i=1;i<=5;)
{
System.out.println("Match" + i);
int inp = sc.nextInt();
int comp = (int)(Math.random()*3);
if(comp==0)
{
System.out.println("computer has rock");
i++;
}
else if(comp==1)
{
System.out.println("computer has paper");
i++;
}
else if(comp==2)
{
System.out.println("computer has scissor ");
i++;
}
if((inp==1&&comp==1)||(inp==2&&comp==2)||(inp==3&&comp==0))
{
b++;
}
else if((inp==1&&comp==2)||(inp==2&&comp==0)||(inp==3&&comp==1))
{
a++;
}
else if((inp-1)==comp)
{
System.out.println("match is tie");
}
else
{
System.out.println("you enter wrong number");
}
}
if(a>b)
{
System.out.println("you are winner");
}
if(a<b)
{
System.out.println("computer is winner");
}
if(a==b)
{
System.out.println("game is tie");
}
}
}