码迷,mamicode.com
首页 > 编程语言 > 详细

java----猜拳(10局分胜负)

时间:2018-05-28 13:39:37      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:new   ||   lse   石头   ring   cas   AC   猜拳游戏   java   

package learning;
import java.util.*;
public class Guess{
public static void main(String [] args){
int j=0;
while(j<4){
int count1=0;
int count2=0;
int count3=0;
for(int i=1;i<11;i++){
System.out.println("-------猜拳游戏-------");
System.out.println("第"+i+"局");
System.out.println("请出拳:(1.剪刀 2.石头 3.布)");
Scanner in = new Scanner(System.in);
int person = in.nextInt();
int computer = (int)(Math.random()*3+1);
String marks = "拳头";
String marks2 = "拳头";
switch(person){
case 1:
marks = "剪刀";
break;
case 2:
marks = "石头";
break;
case 3:
marks = "布";
break;
}
switch(computer){
case 1:
marks2 = "剪刀";
break;
case 2:
marks2 = "石头";
break;
case 3:
marks2 = "布";
break;
}
if (person==computer){
System.out.println("平局,"+"你出的是"+marks+",电脑出的是"+marks2);
count1 =count1+1;
}
else if (person==1&&computer==2||person==2&&computer==3||person==3&&computer==1){
System.out.println("你输了,"+"你出的是"+marks+",电脑出的是"+marks2);
count2 =count2+1;
}
else {
System.out.println("你赢了,"+"你出的是"+marks+",电脑出的是"+marks2);
count3 =count3+1;
}
System.out.println("你赢了"+count3+"局,"+"你输了"+count2+"局,"+"平局"+count1+"局");
}
if(count3>count2){
System.out.println("恭喜你,你赢了!");
break;
}
if(count3<count2){
System.out.println("很遗憾,你输了!");
break;
}
if(count3==count2){
System.out.println("棋逢对手,平局!再来一次吧!");
j++;
continue;
}
}
}
}

java----猜拳(10局分胜负)

标签:new   ||   lse   石头   ring   cas   AC   猜拳游戏   java   

原文地址:https://www.cnblogs.com/choco1986/p/9099549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!