嗨,我想知道如何打印出数组的一个随机值而不是其中的两个。这是我的代码:
public static void main(String args[])
{
String[] currentRoom;
String[][] rooms = new String [2] [2];
rooms [0] [0] = "Start";
rooms [0] [1] = "Treasure Room 1";
rooms [1] [0] = "Goblin Hive 1";
rooms [1] [1] = "Spider Nest";
Random rand = new Random();
{
currentRoom = rooms[rand.nextInt(rooms.length)];
System.out.println(Arrays.toString(currentRoom));
}
}
当我打印出来时,它会从我的数组中说出两个值,例如:[“Start”,“Treasure Room1”],我需要它打印出一个值,例如:[“Start”]或只是 [“Spider Nest1 "]。我想知道如何解决这个问题。
任何帮助表示赞赏:)