java 剪刀石头布 这个游戏怎么用数组来实现,我把脑壳都想破了 100
1个回答
展开全部
import java.util.*;
public class Exam
{
public static void main(String[] args)
{
String[] cq={"石头","剪刀","布"};
String guess;
int youwin=0,mewin=0,daping=0,total=0,n;
Random r=new Random();
Scanner sc=new Scanner(System.in);
while(true)
{
n=r.nextInt(3);
System.out.print("石头、剪刀、布,我已出,请你出(输入exit退出循环):");
guess=sc.nextLine();
if(guess.equals("exit"))
{
break;
}
else
{
total++;
System.out.print("这一次你出的是"+guess+",我出的是"+cq[n]+",所以");
if(guess.equals("石头")&&1==n || guess.equals("剪刀")&&2==n || guess.equals("布")&&0==n)
{
youwin++;
System.out.println("你赢了!");
}
else if(guess.equals(cq[n]))
{
daping++;
System.out.println("我们打平了!");
}
else
{
mewin++;
System.out.println("我赢了!");
}
}
}
System.out.println("总共玩了"+total+"次,你赢了"+youwin+"次,我赢了"+mewin+"次,打平"+daping+"次!");
}
}
public class Exam
{
public static void main(String[] args)
{
String[] cq={"石头","剪刀","布"};
String guess;
int youwin=0,mewin=0,daping=0,total=0,n;
Random r=new Random();
Scanner sc=new Scanner(System.in);
while(true)
{
n=r.nextInt(3);
System.out.print("石头、剪刀、布,我已出,请你出(输入exit退出循环):");
guess=sc.nextLine();
if(guess.equals("exit"))
{
break;
}
else
{
total++;
System.out.print("这一次你出的是"+guess+",我出的是"+cq[n]+",所以");
if(guess.equals("石头")&&1==n || guess.equals("剪刀")&&2==n || guess.equals("布")&&0==n)
{
youwin++;
System.out.println("你赢了!");
}
else if(guess.equals(cq[n]))
{
daping++;
System.out.println("我们打平了!");
}
else
{
mewin++;
System.out.println("我赢了!");
}
}
}
System.out.println("总共玩了"+total+"次,你赢了"+youwin+"次,我赢了"+mewin+"次,打平"+daping+"次!");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询