哪个高手能帮下.怎么写(最好用java或js写) 任意输入0-9中的任何值(牌),且每个值只能输入4次按输入数目计算牌份数(每3个数值为1份,最少份数为4份),按输入顺序发牌,计算哪份最大(mod 10计算) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //随机发牌import java.util.*;public class PlayingCard { private static Random rand = new Random(); private static List<Integer> north = new ArrayList<Integer>(); private static List<Integer> south = new ArrayList<Integer>(); private static List<Integer> west = new ArrayList<Integer>(); private static List<Integer> east = new ArrayList<Integer>(); //各家牌数的点数之和 private static int count1; private static int count2; private static int count3; private static int count4; //0~9张不同的牌,存放到数组中。 private int[] stats = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; // 总的牌数 private int size; public PlayingCard(int size) { this.size = size; } /** * 判断是否已经超过4张牌 * * @param stat * @return */ public boolean out(int num) { return stats[num] >= 4 ? true : false; } /** * 将每次的得到的状态+1,即statn++ * * @param num */ public void setNumber(int num) { stats[num] += 1; } /** * 随机给四家发牌 */ public void dealCard() { for (int i = 0; i < size / 4; i++) { int num1 = rand.nextInt(10); int num2 = rand.nextInt(10); int num3 = rand.nextInt(10); int num4 = rand.nextInt(10); while (out(num1)) { num1 = rand.nextInt(10); } setNumber(num1); while (out(num2)) { num2 = rand.nextInt(10); } setNumber(num2); while (out(num3)) { num3 = rand.nextInt(10); } setNumber(num3); while (out(num4)) { num4 = rand.nextInt(10); } setNumber(num4); south.add(num1); east.add(num2); north.add(num3); west.add(num4); } } //统计各家得到的牌的点数 public void count() { for (int i = 0; i < size /4; i++) { count1 += south.get(i); count2 += east.get(i); count3 += north.get(i); count4 += west.get(i); } } public static void main(String[] args) { //总牌12张,每人3张,牌数可以自己定义多份 PlayingCard playingCard = new PlayingCard(12); //发牌 playingCard.dealCard(); //统计点数 playingCard.count(); System.out.println(south + " = " + count1); System.out.println(east + " = " + count2); System.out.println(north + " = " + count3); System.out.println(west + " = " + count4); }}有用的话,麻烦回个帖子,鼓励下回帖的。呵呵 ~。忘了给最后结果比较大小,楼主自己动手比较下最后几个count就可以得到最大的份了。这里就贴代码了。 二维打砖块小游戏碰撞算法问题 通过java application 中的一个方法,将1-100内随机产生50个数,并打印,再将其中的偶数降序排列,并打印 关于线程问题 我不知道这些是什么程序,应该根JAVA有关系!帮我看看! Frame和Panel有何区别 如何监视线程执行的结果? java网络的问题 在JAVA中,怎样向一个数组输入数据? ResultSet记录集里面的内容如何实现按照某个字段排序?? 通过继承Thread类实现线程与实现Runnable接口实现线程有什么区别 java初学者 高手帮忙啊!!socket 读写问题
//随机发牌
import java.util.*;public class PlayingCard {
private static Random rand = new Random();
private static List<Integer> north = new ArrayList<Integer>();
private static List<Integer> south = new ArrayList<Integer>();
private static List<Integer> west = new ArrayList<Integer>();
private static List<Integer> east = new ArrayList<Integer>();
//各家牌数的点数之和
private static int count1;
private static int count2;
private static int count3;
private static int count4;
//0~9张不同的牌,存放到数组中。
private int[] stats = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
// 总的牌数
private int size; public PlayingCard(int size) {
this.size = size;
} /**
* 判断是否已经超过4张牌
*
* @param stat
* @return
*/
public boolean out(int num) {
return stats[num] >= 4 ? true : false;
} /**
* 将每次的得到的状态+1,即statn++
*
* @param num
*/
public void setNumber(int num) {
stats[num] += 1;
} /**
* 随机给四家发牌
*/
public void dealCard() {
for (int i = 0; i < size / 4; i++) {
int num1 = rand.nextInt(10);
int num2 = rand.nextInt(10);
int num3 = rand.nextInt(10);
int num4 = rand.nextInt(10); while (out(num1)) {
num1 = rand.nextInt(10);
}
setNumber(num1);
while (out(num2)) {
num2 = rand.nextInt(10);
}
setNumber(num2);
while (out(num3)) {
num3 = rand.nextInt(10);
}
setNumber(num3);
while (out(num4)) {
num4 = rand.nextInt(10);
}
setNumber(num4); south.add(num1);
east.add(num2);
north.add(num3);
west.add(num4);
}
}
//统计各家得到的牌的点数
public void count() {
for (int i = 0; i < size /4; i++) {
count1 += south.get(i);
count2 += east.get(i);
count3 += north.get(i);
count4 += west.get(i);
}
}
public static void main(String[] args) {
//总牌12张,每人3张,牌数可以自己定义多份
PlayingCard playingCard = new PlayingCard(12);
//发牌
playingCard.dealCard();
//统计点数
playingCard.count();
System.out.println(south + " = " + count1);
System.out.println(east + " = " + count2);
System.out.println(north + " = " + count3);
System.out.println(west + " = " + count4);
}
}有用的话,麻烦回个帖子,鼓励下回帖的。呵呵