Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class game {
- public static void main(String args[]){
- Scanner input = new Scanner (System.in);
- int userwin=0;
- int compwin=0;
- String[]num;
- num = new String[3];
- num[0]="scissor";
- num[1]="rock";
- num[2]="paper";
- while (compwin<3 && userwin<3){
- System.out.print("scissor (0), rock(1), paper(2): ");
- int user;
- do {
- user = input.nextInt();
- if (user>2)
- System.out.println("You have entered an invalid input. Please enter 0, 1 or
- 2.");
- } while (user>2);
- int comp = (int) (Math.random() * 3);
- if (user==comp)
- System.out.println("The Computer is "+num[comp]+". You are "+num[user]+" too."+"It
- is a draw!");
- else {
- if (user==1)
- if (comp==0){
- System.out.println("The computer is scissor.You are rock.You
- Win!");
- userwin++;
- }
- else if (comp==2){
- System.out.println("The computer is paper.You are rock.You lost!");
- compwin++;
- }
- if (user==2)
- if (comp==0){
- System.out.println("The computer is scissor.You are paper.You
- lost!");
- compwin++;
- }
- else if (comp==1){
- System.out.println("The computer is rock.You are paper.You Win!");
- userwin++;
- }
- if (user==0)
- if(comp==2){
- System.out.println("The computer is paper.You are scissor.You
- win!");
- userwin++;
- }
- else if (comp==1){
- System.out.println("The computer is rock.You are scissor.You
- lost!");
- compwin++;
- }
- } // else
- } // while
- if (compwin>userwin)
- System.out.println("GAME OVER! Computer won the game!");
- else
- System.out.println("HURAH! You won the game!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement