-
Notifications
You must be signed in to change notification settings - Fork 30
/
Java_Game_RockPaperScissor.java
39 lines (38 loc) · 1.52 KB
/
Java_Game_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
package com.company;
import java.util.Scanner;
import java.util.Random;
public class Java_Game_RockPaperScissor {
public static void main(String[] args) {
System.out.println("Welcome To The Rock Paper Scissor Game");
System.out.println("0 For Rock \n1 For Paper \n2 For Scissor");
int i = 0;
while(i<5)
{
System.out.printf("Please Choose Rock or Paper or Scissor\n",i++);
Scanner a = new Scanner(System.in);
int num = a.nextInt();
switch (num){
case 0 -> System.out.println("You Chose Rock");
case 1 -> System.out.println("You Chose Paper");
case 2 -> System.out.println("You Chose Scissor");
}
System.out.println("It's Computer's Turn Now");
Random b = new Random();
int num2 = b.nextInt(3);
switch (num2){
case 0 -> System.out.println("Computer Chose Rock");
case 1 -> System.out.println("Computer Chose Paper");
case 2 -> System.out.println("Computer Chose Scissor");
}
if(num2 == num){
System.out.println("Match Draw!");
}
else if((num==0 && num2==2) || (num==1 && num2==0) || (num==2 && num2==1)){
System.out.println("Congrats!! You Won");
}
else{
System.out.println("You Lost!! Better Luck Next Time :)");
}
}
}
}