Skip to content

Instantly share code, notes, and snippets.

@doubledouble
Created June 9, 2012 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doubledouble/2901847 to your computer and use it in GitHub Desktop.
Save doubledouble/2901847 to your computer and use it in GitHub Desktop.
剪刀石头布
package test;
import java.util.Scanner;
public class ScissorStoneCloth {
/**
* @param args
*/
public static void main(String[] args) {
String[] tips = new String[]{"scissor","stone","cloth"};
System.out.println("input your gesture (0-scissor, 1-stone, 2-cloth)");
int computer = -1;
Scanner in = new Scanner(System.in);
int man = -1;
while(true){
computer = (int) (Math.random()*3);
System.out.print(">>");
try{
man = Integer.parseInt(in.nextLine());
}catch(NumberFormatException e){
}
if(man == -1 || man <0 || man >2){
System.out.println("\ninvalid input ");
continue;
}
System.out.println("your gesture :"+tips[man]+" ;computer gesture :"+tips[computer]);
int result = (man - computer +4)%3 -1;
if(result > 0){
System.out.println("you win!");
}else if(result == 0){
System.out.println("draw");
}else{
System.out.println("you lose");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment