Java 和电脑猜拳

package www;

import java.util.Scanner;

// 石头剪刀布的游戏
public class caiquan {
public static void main(String [] args){
int x=1,count=0;
while(x==1){
System.out.println("1:石头");
System.out.println("2:剪刀");
System.out.println("3:布");

int j=1+(int)(Math.random()*3);
// System.out.println(j);
Scanner a=new Scanner(System.in);
int i=a.nextInt();
switch(j){
case 1:
switch(i){
case 1:System.out.println("平局");break;
case 2:System.out.println("败北");break;
case 3:System.out.println("大获全胜!!");x=0;
break;
}break;
case 2:
switch(i){
case 2:System.out.println("平局");break;
case 3:System.out.println("败北");break;
case 1:System.out.println("大获全胜!!");x=0;
break;
}break;
case 3:
switch(i){
case 3:System.out.println("平局");break;
case 1:System.out.println("败北");break;
case 2:System.out.println("大获全胜!!");x=0;
break;
}break;

}
count++;

}
System.out.println("您通过"+count+"次击败了电脑");
}

}

猜你喜欢

转载自www.cnblogs.com/3w1z3/p/10833769.html