-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
47 lines (41 loc) · 1.24 KB
/
Game.java
File metadata and controls
47 lines (41 loc) · 1.24 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
package com.company;
import java.util.Random;
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
// 0 for Rock
// 1 for Paper
// 2 for Scissor
Scanner sc=new Scanner(System.in);
System.out.println("Enter 0 for Rock,1 for Paper,2 for Scissor ");
int userInput=sc.nextInt();
Random random=new Random();
int ComputerInput= random.nextInt(3);
if (userInput==ComputerInput)
{
System.out.println("Draw");
}
else if (userInput==0 && ComputerInput==2 || userInput==1 && ComputerInput==2 || userInput==2 && ComputerInput==0)
{
System.out.println("You Win !");
}
else {
System.out.println("Computer Win!");
}
if (ComputerInput==0)
{
System.out.println("Computer Choice: Rock");
}
else if (ComputerInput==1)
{
System.out.println("Computer Choice: Paper");
}
else if (ComputerInput==2)
{
System.out.println("Computer Choice: Scissor");
}
else {
System.out.println("Invalid Choice");
}
}
}