即時通訊此新的但即將做一個酒店預訂程序。二維int陣列shuffle
所以我同房間一個二維int數組,當我開始計劃我希望他們在被隨機洗牌,以所謂的RoomNotInUse或RoomInUse(陣列,使得evertime我開始的房間都隨機生成程序。
將是真棒,如果有人知道一種方法解決這個:)
// ARRAYS
protected static int[][] rooms = {
{1,1}, {1,2}, {1,3}, {1,4}, {1,5},
{2,1}, {2,2}, {2,3}, {2,4}, {2,5},
{3,1}, {3,2}, {3,3}, {3,4}, {3,5},
{4,1}, {4,2}, {4,3}, {4,4}, {4,5},
{5,1}, {5,2}, {5,3}, {5,4}, {5,5}
};
//Declare all hotel rooms 5x5, the first number is the floor and the sec is the room
private char[][] ROIU = {
};
//Rooms not in use
private char[][] RIU = {
};
//Rooms in use
public class roomShuffle {
}
//Shuffle all rooms in 2 diffrent arrays, ROIN and RIU
public class RoomNotInUse {
}
//Displayes all the rooms thats not in use
public class RoomInUse {
}
//Displayes all rooms in use
}
我嘗試這樣做,但不能讓它與2D工作。但是,當我讀到有人洗牌時,它說沒有必要列出什麼樣的列表。 – Erazx
@Erazx請參閱我在答案中提供的教程鏈接。這很簡單。 ArrayList,LinkedList ..他們都實現列表。所以選擇你喜歡的。在教程中還有數組隨機播放。如果你願意,可以使用它。 –