我在如何编写代码时写了一个空白。我有一个数组列表,随机选择四个字符串之一。然后基于该选择,我需要在IF
语句中使用它。
这是我的代码,我的最终目标是,如果TEST3
是在上面随机选择的。然后它将保存到platform1并格式化以供显示。然后我需要TEST3
运行if语句来决定是否应该显示其他数字。
public static String platform() {
ArrayList<String> plat = new ArrayList<String>();
plat.add("TEST1");
plat.add("TEST2");
plat.add("TEST3");
plat.add("TEST4");
String platform1 = plat.get(new Random().nextInt(plat.size()));
String platform1_format = String.format("%4s", platform1).replace(' ', ' ');
if (platform1_format.equals("TEST3")) {
ArrayList<String> bankcodes = new ArrayList<String>();
bankcodes.add("012");
bankcodes.add("254");
String bankcodes1 = bankcodes.get(new Random().nextInt(bankcodes.size()));
String bankcodes1_format = String.format("%-6s", bankcodes1).replace(' ', ' ');
} else {
String bankcodes1 = " ";
String bankcodes1_format = String.format("%-6s", bankcodes1).replace(' ', ' ');
}
return platform1_format;
}