标题:求高手指点~
只看楼主
兜兜里有耗子
Rank: 2
等 级:论坛游民
帖 子:16
专家分:18
注 册:2012-10-8
结帖率:100%
已结贴  问题点数:20 回复次数:4 
求高手指点~
小弟做了个发牌的,随机2副牌平均发给4个人,在验证是否拿到重复牌的地方编译错误。


    public static void main(String[] args) {
        String[] card = { "黑桃A", "黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7",
                "黑桃8", "黑桃9", "黑桃10", "黑桃j", "黑桃Q", "黑桃K", "红桃A", "红桃2", "红桃3",
                "红桃4", "红桃5", "红桃6", "红桃7", "红桃8", "红桃9", "红桃10", "红桃J", "红桃Q",
                "红桃K", "方块A", "方块2", "方块3", "方块4", "方块5", "方块6", "方块7", "方块8",
                "方块9", "方块10", "方块J", "方块Q", "方块K", "梅花A", "梅花2", "梅花3", "梅花4",
                "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花11", "梅花12",
                "梅花13" ,"大王","小王","黑桃A", "黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7",
                "黑桃8", "黑桃9", "黑桃10", "黑桃j", "黑桃Q", "黑桃K", "红桃A", "红桃2", "红桃3",
                "红桃4", "红桃5", "红桃6", "红桃7", "红桃8", "红桃9", "红桃10", "红桃J", "红桃Q",
                "红桃K", "方块A", "方块2", "方块3", "方块4", "方块5", "方块6", "方块7", "方块8",
                "方块9", "方块10", "方块J", "方块Q", "方块K", "梅花A", "梅花2", "梅花3", "梅花4",
                "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花11", "梅花12",
                "梅花13" ,"大王","小王"};
        Random r= new Random();
        String[] name={"八戒","悟空","唐僧","沙僧"};
        String[] bajie=new String[card.length/4];
        String[] wukong=new String[card.length/4];
        String[] tangseng=new String[card.length/4];
        String[] shaseng=new String[card.length/4];
        boolean[] used=new boolean[card.length];
        int o=0,p=0,u=0,y=0;
        for(int j=0;true;j++){
            int index=r.nextInt(card.length);
            if(card[index]=card[used]){continue;}//这里编译错误,求指点
            
            if(j%4==0){bajie[o++]=card[index];}
            else if(j%4==1){wukong[p++]=card[index];}
            else if(j%4==2){tangseng[u++]=card[index];}
            else{shaseng[y++]=card[index];}
        }
        System.out.println("八戒拿到的牌"+Arrays.toString(bajie));
        System.out.println("悟空拿到的牌"+Arrays.toString(wukong));
        System.out.println("唐僧拿到的牌"+Arrays.toString(tangseng));
        System.out.println("沙僧拿到的牌"+Arrays.toString(shaseng));
        
        
        
    }

搜索更多相关主题的帖子: 红桃K public 
2012-10-21 14:12
shellingford
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:19
帖 子:228
专家分:1348
注 册:2010-8-9
得分:20 
第一个问题
if里面要双等
= 是赋值语句
== 是判断条件
第二个问题
used是boolean数组 不是int类型
所以card[used]是错误的
第三个问题
for(int j=0;true;j++)
for循环体中没有break语句,同时循环条件永远是true,这个循环是死循环

其他的没细看



[ 本帖最后由 shellingford 于 2012-10-21 15:07 编辑 ]
2012-10-21 15:05
兜兜里有耗子
Rank: 2
等 级:论坛游民
帖 子:16
专家分:18
注 册:2012-10-8
得分:0 
3Q~谢谢
2012-10-21 15:13
兜兜里有耗子
Rank: 2
等 级:论坛游民
帖 子:16
专家分:18
注 册:2012-10-8
得分:0 
回复 2楼 shellingford
第二个问题
used是boolean数组 不是int类型
所以card[used]是错误的
请问下这个怎么处理
2012-10-21 15:17
shellingford
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:19
帖 子:228
专家分:1348
注 册:2010-8-9
得分:0 
回复 4楼 兜兜里有耗子
这句if语句原本是想做什么判断?

boolean[] used=new boolean[card.length];
代码中used只是初始化,并没有赋值或者改变值,那么创建used以后原本是想用来做什么的?
2012-10-21 22:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-383726-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057709 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved