//电脑产生随机数
//调用Scanner类,键盘输入 Random类,产生随机数。
import java.util.Random;
public class add {
public static void main(String[] agrs){
Random in=new Random();
int sum=0;
for(int j=0;j<100;j++){
int i=in.nextInt(100);//产生一百以内的随机数
System.out.println("第"+(j+1)+"个随机数为:"+i);
sum=sum+i;
}
System.out.println("平均值为:"+sum/100);
}
}
//猜拳游戏
import java.util.Scanner;
public class Game{
public static void main(String[] args){
System.out.println("----猜拳游戏----");
System.out.println("请出拳(1.剪刀,2.石头,3.布)");
Scanner in=new Scanner(System.in);
int person=in.nextInt();
int window=(int)(Math.random()*3)+1;//从0开始,为了迎合以上,加一。
String A="拳头";//这是做一个标记
String B="拳头";
switch(person){
case 1:
A="剪刀";
break;
case 2:
A="石头";
break;
case 3:
A="布";
break;
}
switch(window){
case 1:
B="剪刀";
break;
case 2:
B="石头";
break;
case 3:
B="布";
break;
}
System.out.println("你出的是:"+A);
System.out.println("电脑出的是:"+B);
if(person==window){
System.out.println("平局");
}else if(person==1&&window==2||person==2&&window==3||person==3&&window==1){
System.out.println("您输了!");
}else{
System.out.println("您赢了!!");
}
}
}