-
Notifications
You must be signed in to change notification settings - Fork 0
/
rockpaperscissor.java
57 lines (46 loc) · 1.96 KB
/
rockpaperscissor.java
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
import javax.swing.*;
import java.util.Random;
import java.util.Scanner;
public class rockpaperscissor {
public static void main(String[] args) {
Random rad = new Random();
Scanner sc= new Scanner(System.in);
System.out.println("enter your choice");
String user = sc.next();
int num= rad.nextInt(3);
//System.out.println(" here in this game 0 for rock 1 for paper and 2for scissor");
String computer;
switch (num) {
case 0:
computer = "rock";
System.out.println("computer choice is rock");
break;
case 1:
computer = "paper";
System.out.println("computer chouce os paper");
break;
case 2 :
computer = "scissor";
System.out.println("computer chouce is scissor");
break;
default:
throw new IllegalStateException("Unexpected value: " + num);
}
if (computer.equals(user)) {
System.out.println("the match is drawn");
}
else if (computer.equals("rock") && user.equals( "paper")) {
System.out.println(" user paper is won");
} else if (computer.equals("rock") && user.equals("scissor")) {
System.out.println("rock is won");
} else if (computer.equals("paper") && user.equals("rock")) {
System.out.println("paper is won");
} else if (computer.equals("paper") && user.equals("scissor")) {
System.out.println(" user scissor is won");
} else if (computer.equals("scissor") && user.equals("rock")) {
System.out.println(" user rock is won");
} else if (computer.equals("scissor") && user.equals("paper")) {
System.out.println("scissor is won");
}
}
}