j_inetaddress.java
来自「一个十分好的java基础学习的课件」· Java 代码 · 共 49 行
JAVA
49 行
// ////////////////////////////////////////////////////////
//
// J_InetAddress.java
//
// Created by Jun-Hai Yong, on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
// Demonstrating the function of the InetAddress class.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
// Jun-Hai Yong. Programming in Java.
// Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
// 雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////
import java.net.InetAddress;
import java.net.UnknownHostException;
public class J_InetAddress
{
public static void main(String args[])
{
String s = "www.tsinghua.edu.cn";
InetAddress ts= null;
try
{
ts = InetAddress.getByName(s);
}
catch (UnknownHostException e)
{
System.err.println(e);
}
if (ts!=null)
{
System.out.println("The IP address of Tsinghua is "
+ ts.getHostAddress( ));
System.out.println("The host name of Tsinghua is "
+ ts.getHostName( ));
}
else System.out.println("Cannot access " + s);
} // End of method: main
} // End of class: J_InetAddress
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?