纸牌比大小java代码 扑克牌比大小java编程( 三 )


JAVA编程判断扑克牌大小import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ListString list = new ArrayListString();
while (scanner.hasNextLine()) {
String string = scanner.nextLine();
list.add(string);
if (list.size() == 5) {
int r = getCard(list);
System.out.println(r);
list.clear();
}
}
}
private static int getCard(ListString list) {
int temp = 7;
int size = list.size();
ListString numList = new ArrayListString();
SetString numSet = new TreeSetString();
ListString colourList = new ArrayListString();
SetString colourSet = new TreeSetString();
for (int i = 0; ilist.size(); i++) {
String num = list.get(i).split(" ")[0];
String colour = list.get(i).split(" ")[1];
【纸牌比大小java代码 扑克牌比大小java编程】if (num.equals("J")) {
numList.add("11");
numSet.add("11");
} else if (num.equals("Q")) {
numList.add("12");
numSet.add("12");
} else if (num.equals("K")) {
numList.add("13");
numSet.add("13");
} else if (num.equals("A")) {
numList.add("14");
numSet.add("14");
} else {
numList.add(num);
numSet.add(num);
}
colourList.add(colour);
colourSet.add(colour);
}
// 同花顺,或者同花
if (colourSet.size() == 1) {
Collections.sort(numList);
for (int i = 0; inumList.size() - 1; i++) {
if (Integer.parseInt(numList.get(i + 1)) - Integer.parseInt(numList.get(i)) == 1) {
if (i == numList.size() - 2) {
temp = 1;
}
continue;
} else {
if (temp4) {
temp = 4;
}
}
}
}
// 四条或者葫芦
if (numSet.size() == 2) {
Collections.sort(numList);
// 四条
if (!numList.get(0).equals(numList.get(1)) || !numList.get(size - 1).equals(numList.get(size - 2))) {
if (temp2) {
temp = 2;
}
} else {
if (temp3) {
temp = 3;
}
}
}
// 三条
if (numSet.size() == 3) {
if (temp6) {
temp = 6;
}
}
// 顺子
if (colourSet.size()1) {
Collections.sort(numList);
for (int i = 0; inumList.size() - 1; i++) {
if (Integer.parseInt(numList.get(i + 1)) - Integer.parseInt(numList.get(i)) == 1) {
if (i == numList.size() - 2) {
if(temp5){
temp = 5;
}
}
} else {
break;
}
}
}
return temp;
}
}
关于纸牌比大小java代码和扑克牌比大小java编程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读