gpt4 book ai didi

Java程序在同一个try and catch中查找以下网站的IP地址: Facebook , google , yahoo

转载 作者:行者123 更新时间:2023-12-02 04:50:03 25 4
gpt4 key购买 nike

这是我的一个网站的代码,但我需要在同一个 try and catch 中创建多个 ip

package javaapplication1;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class JavaApplication1 {

public static void main(String[] args) {
try {
InetAddress[] addresses = InetAddress.getAllByName("google.com");

for (InetAddress address : addresses) {
System.out.println(address);


}
} catch (UnknownHostException ex) {
System.out.println("Could not find");
}
}
}

最佳答案

制作 Facebook、Google 和 yahoo 的列表

迭代列表,然后使用InetAddress.getAllByName(list.get(index))

ArrayList<String> list = new ArrayList<>();
list.add("Facebook");// can add more urls
for (String ip : list) {
try {
InetAddress[] addresses = InetAddress.getAllByName(ip);

for (InetAddress address : addresses) {
System.out.println(address);

}
} catch (UnknownHostException ex) {
System.out.println("Could not find");
}
}

关于Java程序在同一个try and catch中查找以下网站的IP地址: Facebook , google , yahoo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29315935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com