repl.it
@imigames/

rock.paper.scisors

Java

No description

fork
loading
Files
  • Main.java
Main.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
58
59
60
import java.util.Random;
import java.util.Scanner;

class Main {
String rock = "r";
String paper = "p";
String scisors = "s";
static String player;
static Scanner input = new Scanner(System.in);
static Random rand = new Random();
static String comp;
static String player_choice;
  public static void main(String[] args) {
    while(true){
    System.out.println("************************************");
    System.out.println("Chose Rock(r) , Paper(p), Scisors(s)");
    int computer = rand.nextInt(3) + 1;
    if (computer == 1){
      comp = "Rock";
    }
    else if(computer == 2){
      comp = "Paper";
    }
    else if(computer == 3) {
      comp = "Scisors";
      }
    player = input.next();
    if (player.equalsIgnoreCase("r")){
        player_choice = "Rock";}
    else if (player.equalsIgnoreCase("p")){
        player_choice = "Paper";}
    else if (player.equalsIgnoreCase("s")){
        player_choice = "Scisors";}
    else{break;}
    System.out.println("Player             Computer");
    System.out.println(player_choice +"     vs     "+ comp);
    if (player_choice == comp){
      System.out.println("Draw");
    }
    else if (player_choice =="Rock" && comp=="Paper"){
      System.out.println("Computer Wins");
    }
    else if (player_choice =="Rock" && comp=="Scisors"){
      System.out.println("Player Wins");
    }
    else if (player_choice =="Paper" && comp=="Scisors"){
      System.out.println("Computer Wins");
    }
    else if (player_choice =="Paper" && comp=="Rock"){
      System.out.println("Player Wins");
    }
    else if (player_choice =="Scisors" && comp=="Paper"){
      System.out.println("Player Wins");
    }
    else if (player_choice =="Scisors" && comp=="Rock"){
      System.out.println("Computer Wins");
    }
    }
  }
}