第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

比較大小的問(wèn)題,為什么經(jīng)常會(huì)錯(cuò)誤輸出1獲勝,有時(shí)候又會(huì)輸出2獲勝??還有我注釋的那行是什么意思?

package?cardPlay;

import?java.util.*;





public?class?Text?{
public?List<card>??cardList=new?ArrayList<card>()?;
List<player>?player?=?new?ArrayList<player>();


//創(chuàng)建卡牌
public?void?cardAdd(){
	?String[]?nums={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
	?String[]?colors={"黑桃","紅桃","梅花","方塊"};
for(int?i=0;i<4;i++){
for(int?j=0;j<13;j++){
	card?c=new?card((colors[i]),(nums[j]));
	cardList.add(c);
}	
}
System.out.println("創(chuàng)建卡牌成功");
for(card?x:cardList)
	System.out.print(x.color+x.num+",");

System.out.println();}
//洗牌
public?void?change(){
	Random?random=new?Random();
	for(int?i=0;i<4;i++){
		int?k=cardList.size();
		Integer?j=random.nextInt(k);
		card?temp=(card)cardList.get(j);
		cardList.remove(temp);
		cardList.add(i,temp);
	}
	System.out.println("洗牌結(jié)束");
	for(card?x:cardList)
		System.out.print(x.color+x.num+",");

}
//創(chuàng)建玩家
public?void?playerAdd(){
	int?i=0;
	while(i<1){

	try{		System.out.println("輸入第一個(gè)玩家ID");??
	Scanner?scan=new?Scanner(System.in);
		int?id1=scan.nextInt();
		System.out.println("輸入第一個(gè)玩家姓名");
		String?name1=scan.next();
		player?player1=new?player(id1,name1);
	i++;
	player.add(player1);}catch(Exception?e){
		System.out.println("請(qǐng)輸入整數(shù)數(shù)字");
	}}
	

	i=0;
	while(i<1){
	try{	System.out.println("輸入第二個(gè)玩家ID");
	Scanner?scan=new?Scanner(System.in);
	int	id2=scan.nextInt();
	System.out.println("輸入第二個(gè)玩家姓名");
	String?name2=scan.next();
	player?player2=new?player(id2,name2);
	i++;
	player.add(player2);}catch(Exception?e){
		System.out.println("請(qǐng)輸入整數(shù)數(shù)字");
	}}


	
}
//比較大小
public?void?comparator(){
????Compare?compare?=?new?Compare();
List<card>?com=new?ArrayList<card>();
List<card>?max=new?ArrayList<card>();
com.add(cardList.get(0));
com.add(cardList.get(1));
com.add(cardList.get(2));
com.add(cardList.get(3));
System.out.println(player.get(0).name+"有卡牌"+com.get(0).num+com.get(0).color+com.get(2).num+com.get(2).color);
System.out.println(player.get(1).name+"有卡牌"+com.get(1).num+com.get(1).color+com.get(3).num+com.get(3).color);
max.add(com.get(0));
Collections.sort(com,compare);//這句話是什么意思???
for(int?i=1;i<4;i++){
if(compare.compare(com.get(i),max.get(0))>0)
max.add(0,com.get(i));
}
	if(max.get(0).equals(cardList.get(0))||max.get(0).equals(cardList.get(2)))
		System.out.println(player.get(0).name+"獲勝");
		else?
			System.out.println(player.get(1).name+"獲勝");
	
	
}

	


public?static?void?main(String[]?args){
	Text?text=new?Text();
	text.cardAdd();
	text.change();
text.playerAdd();
text.comparator();
}}
package?cardPlay;

public?class?card?{
public?String?color;
public?String?num;
public?card(String?color,String?num){
	this.color=color;
	this.num=num;
}



}
package?cardPlay;

import?java.util.HashSet;
import?java.util.Set;

public?class?player?{
public?int?id;
public??String?name;
public?Set?cards;
public?player(int?id,String?name){
	this.id=id;
	this.name=name;
	this.cards=new?HashSet();
}
}
package?cardPlay;

import?java.util.Arrays;
import?java.util.Comparator;
import?java.util.List;
/**
?*?比較規(guī)則
?*?@author?jelly
?*
?*/
public?class?Compare?implements?Comparator<card>?{
?
????@Override
????public?int?compare(card?o1,card?o2)?{
?
????????List<String>?nums?=?Arrays.asList("2",?"3",?"4",?"5",?"6",?"7",?"8",
????????????????"9",?"J",?"Q",?"K",?"A");
????????List<String>?color?=?Arrays.asList("方塊",?"梅花",?"紅桃",?"黑桃");
????????if?(nums.indexOf(o1.num)?==?nums.indexOf(o2.num))
????????????return?(((Integer)?(color.indexOf(o1.color)))
????????????????????.compareTo((Integer)?(color.indexOf(o2.color))));
????????else?{
????????????return?(((Integer)?nums.indexOf(o1.color)))
????????????????????.compareTo(((Integer)?nums.indexOf(o2.color)));
????????}
????}
}

589f28de00015c2e01670065.jpg

589f28df00019dea01650067.jpg

589f28df00018a8801690074.jpg


正在回答

0 回答

舉報(bào)

0/150
提交
取消

比較大小的問(wèn)題,為什么經(jīng)常會(huì)錯(cuò)誤輸出1獲勝,有時(shí)候又會(huì)輸出2獲勝??還有我注釋的那行是什么意思?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)