【发布时间】:2020-12-29 10:26:56
【问题描述】:
public static void main (String[] args) throws java.lang.Exception{
ArrayList friends = new ArrayList<>(asList("Danny", "Benni", "Marcus", "Pat"));
ArrayList Places = new ArrayList<>(asList("Paris", "Brasil", "Miami", "Jamaica"));
ArrayList Gifts = new ArrayList<>(asList("Snacks", "Photos", "Instrument", "Whine"));
ArrayList[] travelgoals = new ArrayList<>{Places, Gifts};
for (int b = 0; b > friends.length; b++){
if(b > Places.length) {
System.out.println(Places.get().Random((0), Places.length);
}if (b > Gifts.length) {
System.out.println(Gifts.get().Random((0), Gifts.length);
}
}else {
System.out.println("Looks like you got off scottfree!");
}
}
您好,我正在尝试使用字符串数组来打印位置中的随机目标,但我认为我还远远不够。
【问题讨论】:
-
您是如何决定在 .get() 的结果上调用
.Random()的?? -
Java 命名约定的方法和变量以小写字母开头。
-
@azro 我的逻辑是使用 .Random() 从该数组中随机选择一个条目。我的目标是打印朋友的名字以及随机地点和随机礼物
-
@NomadMaker 你是对的。我有点忘记了这一点,因为我正在处理字符串并想用一种方法来处理这一切。
-
我知道了,但是为什么你认为你存在一个 .Random() 方法,因为它根本不存在
标签: java arrays string arraylist random