Created
June 9, 2012 17:17
-
-
Save doubledouble/2901847 to your computer and use it in GitHub Desktop.
剪刀石头布
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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