Advertisement
brilliant_moves

game.java

Jun 22nd, 2015
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class game {
  4.     public static void main(String args[]){
  5.         Scanner input = new Scanner (System.in);
  6.         int userwin=0;
  7.         int compwin=0;
  8.         String[]num;
  9.         num = new String[3];
  10.         num[0]="scissor";
  11.         num[1]="rock";
  12.         num[2]="paper";
  13.         while (compwin<3 && userwin<3){
  14.             System.out.print("scissor (0), rock(1), paper(2): ");
  15.             int user;
  16.             do {
  17.                 user = input.nextInt();
  18.                 if (user>2)
  19.                     System.out.println("You have entered an invalid input. Please enter 0, 1 or
  20. 2.");
  21.             } while (user>2);
  22.             int comp = (int) (Math.random() * 3);
  23.             if (user==comp)
  24.                 System.out.println("The Computer is "+num[comp]+". You are "+num[user]+" too."+"It
  25. is a draw!");
  26.             else {
  27.                 if (user==1)
  28.                     if (comp==0){
  29.                         System.out.println("The computer is scissor.You are rock.You
  30. Win!");
  31.                         userwin++;
  32.                     }
  33.                     else if (comp==2){
  34.                         System.out.println("The computer is paper.You are rock.You lost!");
  35.                         compwin++;
  36.                     }
  37.                 if (user==2)
  38.                     if (comp==0){
  39.                         System.out.println("The computer is scissor.You are paper.You
  40. lost!");
  41.                         compwin++;
  42.                     }
  43.                     else if (comp==1){
  44.                         System.out.println("The computer is rock.You are paper.You Win!");
  45.                         userwin++;
  46.                     }
  47.                 if (user==0)
  48.                     if(comp==2){
  49.                         System.out.println("The computer is paper.You are scissor.You
  50. win!");
  51.                         userwin++;
  52.                     }
  53.                     else if (comp==1){
  54.                         System.out.println("The computer is rock.You are scissor.You
  55. lost!");
  56.                         compwin++;
  57.                     }
  58.             } // else
  59.         } // while
  60.         if (compwin>userwin)
  61.             System.out.println("GAME OVER! Computer won the game!");
  62.         else
  63.             System.out.println("HURAH! You won the game!");
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement