java.net.InetAddress Class has a static method getLocalHost method which returns Object of localHost Then GetHostAddress Method Returns the IP address string in textual presentation. So in Your program use following line to print IP Address.

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

public class IPAdress {

  public static void main(String[] args) {
    try {
      System.out.println(InetAddress.getLocalHost().getHostName());
      System.out.println(InetAddress.getLocalHost().getHostAddress());
      
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }

  }

}