+ 7
Error
My code is showing access error..... Please tell me how to solve this... https://code.sololearn.com/c5y5OFI5L5Qt/?ref=app
1 Answer
+ 2
import java.net.*;
public class Program
{
public static void main(String[] args) throws UnknownHostException
{
System.out.println(InetAddress.getLocalHost());
}
}
get localHost() is a static method which returns an object from type InetAddress.
InetAddress IP = InetAddress.getLocalHost(); should also work.
It can throw an exception which you need to handle, otherwise you get an error message.