我试图在每个循环中使用列表中的其他IP地址。然后它回到起点,并重新进行一次。但是我很困惑[关闭]

问题描述 投票:-1回答:1
private static int[] values = {8, 6, 14, 24, 2}; //

public static int index = -1;

public static int count() {
    return values[++index % values.length];
}
System.out.println(count())

这就是我用来做常规数字的方法,但是当我开始使用121.12.23.4之类的IP地址时,它是行不通的。显然是因为它不是int,但我想知道如何使用IP地址。

java
1个回答
-2
投票

有帮助吗?

private static String[] ips = {"121.2.4.10","192.153.4.8","221.2.3.1"}; //

public static int index = -1;

public static String next() {
    return ips[++index % ips.length];
}

System.out.println(next());
© www.soinside.com 2019 - 2024. All rights reserved.