Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:一道面试题,向大家请教!(在线等) [Re:toupeen]
ycxct





发贴: 18
积分: 0
于 2006-12-19 22:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

class card implements Comparable<card> {
private int color; //1-4
private int point; //1-13
card(int color, int point) {
this.color = color;
this.point = point;
}

public int compareTo(card cobj) {
return color * 10 + point - (cobj.color * 10 + cobj.point);
}

public String toString() {
String str=null;
switch (color) {
case 0:
str = "桃";
break;
case 1:
str = "心";
break;
case 2:
str = "梅";
break;
case 3:
str = "方";
break;
}
switch(point)
{
case 0:
str += " A";
break;
case 10:
str += " J";
break;
case 11:
str += " Q";
break;
case 12:
str += " K";
break;
default:
str+=" "+ (point+1);
}
return str;
}
}

public class test {
public static void main(String[] args) {
ArrayList<card> pk=new ArrayList<card>();
for (int i = 0; i < 52; i++) {
pk.add(new card((i/13)%4,i%13));
}
System.out.println(pk);
Collections.shuffle(pk); //洗牌
System.out.println(pk);
Collections.sort(pk); //排序
System.out.println(pk);
}
}


ycxct edited on 2006-12-19 22:40


Java应用者与<IDE/环境>

话题树型展开
人气 标题 作者 字数 发贴时间
26875 一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) toupeen 134 2006-12-13 17:40
26162 Re:一道面试题,向大家请教!(在线等) luozhe0107 222 2006-12-15 10:47
23911 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) renchao775 12 2007-03-20 09:53
22043 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) aaarong 215 2007-03-21 20:49
23565 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) zip2007 5 2007-03-27 20:33
21920 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) xuxiaolei 898 2007-03-28 19:49
21928 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) xuxiaolei 374 2007-03-29 07:55
21659 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) wxnis1 82 2007-04-01 21:49
20911 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) suntao19830709 131 2007-04-28 13:29
22573 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) xiezhuojun2006 10 2007-05-05 23:31
20341 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) andy_wang_5 1451 2007-06-22 14:36
24376 Re:一道面试题,向大家请教!(在线等) ycxct 1463 2006-12-19 22:25
26038 Re:一道面试题,向大家请教!(在线等) luozhe0107 14 2006-12-22 12:27
25880 Re:一道面试题,向大家请教!(在线等) dreamsky2 130 2006-12-22 14:22
21111 Re:一道面试题,向大家请教!(在线等) liangzi232004 204 2007-06-21 16:19
26181 Re:一道面试题,向大家请教!(在线等) ycxct 25 2006-12-22 17:29
25383 Re:楼上的太烦了,搞个简单的 liushuiboy 588 2007-01-24 12:41
25462 Re:一道面试题,向大家请教!(在线等) java658 4 2007-01-26 10:32
25484 Re:一道面试题,向大家请教!(在线等) ken_chie 51 2007-01-26 12:52
24773 Re:一道面试题,向大家请教!(在线等) xiaofengtoo 113 2007-02-19 13:35
22721 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) sljliuan001 2056 2007-02-24 20:53
22007 Re:一道面试题,向大家请教!(把扑克数组按花型和大小排列;模仿洗牌) dorrenchen 953 2007-03-19 14:09

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923