Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
剪刀石头布
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
You can’t perform that action at this time.