import java.util.*;
class Demo1_Random {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int x,xx,y,yy;
x=xx=y=yy=0;
String[] arr={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};//定义牌
while(true) {
System.out.print("电脑出牌:");
for(int i=0;i<3;i++){ //出3张随机牌
x=(int)(Math.random()*13);
System.out.print(arr[x]+" ");//电脑的输出3张随机牌
xx+=x; //记录总数
}
System.out.println(); //换行
System.out.print("你出牌:"); //我方的输出3张随机牌
for(int i=0;i<3;i++){
y=(int)(Math.random()*13);
System.out.print(arr[y]+" ");
yy+=y; //记录总数
}
System.out.println();
if (xx>yy) {
System.out.println("电脑出的牌比你大:"+(xx-yy)+"点");
}else if(xx<yy){
System.out.println("你出的牌比电脑大:"+(yy-xx)+"点");
}else {
System.out.println("平局哦!");
}
System.out.println("继续请按1,按其她键退出!");
int z=sc.nextInt();
if (z!=1) {
break;
}
}
}
}
|
|