import java.util.Random;
import java.util.Scanner;
public class youxij {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("scissor(0),rock(1),paper(2):");
int num = input.nextInt();
Random rand = new Random();
int com = (int)(Math.random()*10%3);
switch(com) {
case 0:System.out.print("The computer is scissor.");break;
case 1:System.out.print("The computer is rock.");break;
case 2:System.out.print("The computer is paper.");
}
switch(num) {
case 0:System.out.print("You are scissor.");break;
case 1:System.out.print("You are rock.");break;
case 2:System.out.print("You are paper.");
}
if(num == com){
System.out.println("It is a draw");
}else if((com == 0 && num ==1)||(com == 1 && num ==2)||(com == 2 && num ==1)){
System.out.println("You won");
}else {
System.out.println("You lost");
}
}
}
Math.random()函数
random()函数会产生一个0----0.9999999的随机数。
(int )(Math.random()*10)会产生一个0------9的整数。