-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.java
More file actions
34 lines (31 loc) · 990 Bytes
/
Game1.java
File metadata and controls
34 lines (31 loc) · 990 Bytes
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
package sample;
import javax.swing.*;
import java.util.Scanner;
import java.util.Random;
public class Game1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random rd = new Random();
System.out.println("Enter 0 for rock,1 for paper or 2 for scissor");
int input = sc.nextInt();
int computerinput = rd.nextInt(3);
if(input ==0 && computerinput==2 || input==1 && computerinput==0 || input==2 && computerinput==1){
System.out.println("You win");
}
else if(input==computerinput){
System.out.println("Match Drawn");
}
else{
System.out.println("Computer wins");
}
if(computerinput==0) {
System.out.println("Computer choice-rock");
}
else if(computerinput==1){
System.out.println("Computer choice-paper");
}
else{
System.out.println("Computer choice-scissor");
}
}
}