You are pretty close - just a bit more coding to make it visible:
Try this:
public static void main(String[] args) {
try {
InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress();
String hostname = addr.getHostName();
System.out.println("hostname " + hostname);
System.out.println("IP Address " + convertIP(ipAddr));
} catch (java.net.UnknownHostException e) {
e.printStackTrace();
}
}
private static String convertIP(byte[] ipAddr){
String ipAddrStr = "";
for (int i=0; i<ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i]&0xFF;
}
return ipAddrStr;
}