在Java中,可以使用以下方式将等待名单分配给所有6个展位:
以下是一个示例代码:
import java.util.ArrayList;
import java.util.List;
public class BoothAllocation {
public static void main(String[] args) {
List<String> waitingList = new ArrayList<>();
waitingList.add("Person A");
waitingList.add("Person B");
waitingList.add("Person C");
waitingList.add("Person D");
waitingList.add("Person E");
waitingList.add("Person F");
String[] booths = new String[6];
for (int i = 0; i < waitingList.size(); i++) {
if (i < booths.length) {
booths[i] = waitingList.get(i);
System.out.println("Allocated booth " + (i + 1) + " to " + booths[i]);
} else {
System.out.println("No more booths available for " + waitingList.get(i));
}
}
}
}
运行以上代码,将会输出以下结果:
Allocated booth 1 to Person A
Allocated booth 2 to Person B
Allocated booth 3 to Person C
Allocated booth 4 to Person D
Allocated booth 5 to Person E
No more booths available for Person F
这样,等待名单中的所有人都被分配了展位。请注意,以上示例代码仅为演示目的,实际应用中可能需要根据具体需求进行适当修改。
领取专属 10元无门槛券
手把手带您无忧上云