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

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

在判斷玩家ID中的問(wèn)題、求大神

package?com.joker.test;

import?java.util.ArrayList;
import?java.util.Iterator;
import?java.util.List;
import?java.util.Map;
import?java.util.Scanner;

import?com.joker.entity.Player;
import?com.joker.entity.Poker;

public?class?PokerGame?{
	Map<Integer,?Player>?playerMap;
	List<Poker>?pokerList;
	Scanner?input;
	String[]?type?=?{?"黑桃",?"紅桃",?"梅花",?"方塊"?};
	String[]?pointer?=?{?"2",?"3",?"4",?"5",?"6",?"7",?"8",?"9",?"10",?"J",
			"Q",?"K",?"A"?};

	public?PokerGame()?{
		pokerList?=?new?ArrayList<Poker>();
		input?=?new?Scanner(System.in);

	}

	/**
	?*?創(chuàng)建撲克牌
	?*?
	?*?@param?args
	?*/
	public?void?pokerAdd()?{
		System.out.println("-------創(chuàng)建撲克牌-------");
		for?(int?i?=?0;?i?<?type.length;?i++)?{
			for?(int?j?=?0;?j?<?pointer.length;?j++)?{
				pokerList.add(new?Poker(type[i],?pointer[j]));
			}
		}
		System.out.println("-------撲克牌創(chuàng)建成功-------");
	}

	/**
	?*?遍歷顯示所有撲克牌
	?*?
	?*?@param?args
	?*/
	public?void?pokerGet()?{
		for?(Iterator<Poker>?it?=?pokerList.iterator();?it.hasNext();)?{
			for?(int?i?=?0;?i?<?type.length;?i++)?{
				for?(int?j?=?0;?j?<?pointer.length;?j++)?{
					Poker?poker?=?it.next();
					System.out
							.print(poker.getType()?+?poker.getPointer()?+?"?");
				}
				System.out.println();
			}
		}

	}

	/**
	?*?創(chuàng)建玩家
	?*?
	?*?@param?args
	?*/
	public?void?playerAdd()?{
		System.out.println("-------創(chuàng)建玩家-------");
		int?i?=?0;
		while?(i?<?2)?{
			System.out.println("請(qǐng)輸入玩家的ID:");
			int?id;
			try?{
				id?=?input.nextInt();
				Player?playerID?=?playerMap.get(id);
				if?(playerID?==?null)?{
					System.out.println("請(qǐng)輸入玩家的姓名:");
					String?name?=?input.next();
					Player?player?=?new?Player(id,?name);
					playerMap.put(id,?player);
					System.out.println("成功創(chuàng)建玩家:"?+playerMap.get(id).getName());
					System.out.println("--------------------");
					i++;
				}?else?{
					System.out.println("該ID已被占用~~");
					continue;
				}
			}?catch?(Exception?e)?{
				System.out.println("請(qǐng)輸入整數(shù)類型ID!!");

				continue;
			}
		}
	}

	public?static?void?main(String[]?args)?{
		PokerGame?pg?=?new?PokerGame();

		pg.pokerAdd();
		pg.pokerGet();
		pg.playerAdd();
	}

}

為什么我在try-catch語(yǔ)句中會(huì)出現(xiàn)死循環(huán)錯(cuò)誤輸出???求大神指導(dǎo)該怎么改??

http://img1.sycdn.imooc.com//55ee8da2000159bf05830444.jpg

正在回答

3 回答

Scanner 對(duì)象最好不要重復(fù)使用,在id=input.nextInt();上面新建一個(gè)Scanner對(duì)象就可以了,要放在try語(yǔ)句塊中,我也遇到了這樣的問(wèn)題,就是這樣解決的

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

碼農(nóng)_鑫森淼焱垚 提問(wèn)者

非常感謝!
2015-09-13 回復(fù) 有任何疑惑可以回復(fù)我~

http://zhidao.baidu.com/link?url=vm_Aygd2FHYeWf5cUqzZKV3fakn7c-HLbk6qGmyTzj1I3x9vHTbTh7wCkQ38fshRTBBLuTmc45coXzXb2TJphJKu1ARC2lh-3dySI4ETf-7

按方法修改后,你的代碼仍有bug

73行拋出java.lang.NullPointerException。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

碼農(nóng)_鑫森淼焱垚 提問(wèn)者

謝謝了、、已經(jīng)找到解決辦法了、是因?yàn)樵跇?gòu)造方法中沒(méi)有添加如下代碼 public PokerGame() { pokerList = new ArrayList<Poker>(); playerMap = new HashMap<Integer, Player>(); }
2015-10-16 回復(fù) 有任何疑惑可以回復(fù)我~

在創(chuàng)建玩家方法中playerAdd() 的

id=input.nextInt();上面添加一句這個(gè)試試

Scanner input=new Scanner(System.in);

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

碼農(nóng)_鑫森淼焱垚 提問(wèn)者

還是不行、、死循環(huán)這個(gè)問(wèn)題解決了、但是在你輸入錯(cuò)誤之后再次輸入正確的數(shù)字時(shí)還是判斷錯(cuò)誤~~~
2015-09-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

在判斷玩家ID中的問(wèn)題、求大神

我要回答 關(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)