最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定

在判斷玩家ID中的問題、求大神

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("請輸入玩家的ID:");
			int?id;
			try?{
				id?=?input.nextInt();
				Player?playerID?=?playerMap.get(id);
				if?(playerID?==?null)?{
					System.out.println("請輸入玩家的姓名:");
					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("請輸入整數(shù)類型ID!!");

				continue;
			}
		}
	}

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

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

}

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

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

正在回答

3 回答

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

0 回復 有任何疑惑可以回復我~
#1

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

非常感謝!
2015-09-13 回復 有任何疑惑可以回復我~
0 回復 有任何疑惑可以回復我~
#1

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

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

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

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

Scanner input=new Scanner(System.in);

0 回復 有任何疑惑可以回復我~
#1

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

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

舉報

0/150
提交
取消

在判斷玩家ID中的問題、求大神

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

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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