Package Com.javasm.exerices02;import Java.util.arraylist;import Java.util.list;import java.util.Random;import java.util.scanner;/** * *todo stone scissors cloth scissors game, three innings two wins * @author Caolei May 2, 2018 afternoon 10:51:23 * RockPaperScissors */public class Rock Paperscissors {//For storing scissors result private static list<string> gameresult;public static void Crguessinggame (Scanner SC) { Gameresult = new arraylist<string> ();//store result set char[] finger = {' Hammer ', ' cut ', ' package '};//used to receive each scissors result String result;//for computer Scissors random random = new random ();//record computer wins int computerwinnumber = 0;//count player wins int playerwinnumber = 0;//record scissors First round int i = 0;//Loop out fist while (true) {System.out.println ("+ (i + 1) +" turn, please punch: ");//Computer generated random number int computerget = Random.nextint (3);//user output into the number int playerinput = Sc.nextint ();//Record scissors result = Finger[computerget] + "," + finger[playerinput];//put the result into the collection Gameresult . Add (Result),/* * First to determine results by if * * if (Computerget = = 0 && playerinput! = 0) {* if (playerinput = = 1) * Computer winnumber++; * playerwinnumber++; * * } else if (Computerget = = 1 && playerinput! = 1) {* if (playerinput = = 2) * computerwinnumber++; * playerwinnumber++; *} else if (Computerget = = 2 && playerinput! = 2) {* if (Playerinput = = 0) * computerwinnumber++; * playerwinnumber++; *} *//** * The second result */switch (computerget) {case 0:if (playerinput = 1) computerwinnumber++;if (playerinput = 2) p Layerwinnumber++;break;case 1:if (Playerinput = = 2) computerwinnumber++;if (playerinput = 0) playerWinNumber++;break; Case 2:if (Playerinput = = 0) computerwinnumber++;if (playerinput = = 1) playerwinnumber++;break;default:break;} Record the number of game rounds i++;//determine if anyone wins if (Computerwinnumber = = 2 | | playerwinnumber = = 2) {break;}} Judging the winner if (Computerwinnumber > Playerwinnumber) {System.out.println ("Computer wins!") ");} else {System.out.println ("Congratulations on your victory! ");} Output scissors Results System.out.println ("Concrete results are as follows:"); SYSTEM.OUT.PRINTLN ("Computer, you"); for (String Results:gameresult) {System.out.println ("{" + results + "}");}}}
Scissors game three innings and two wins------Java implementation code