0% found this document useful (0 votes)
45 views2 pages

Ajp Exp 14

AJP practical output prints ✅

Uploaded by

sohamsonar200477
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Ajp Exp 14

AJP practical output prints ✅

Uploaded by

sohamsonar200477
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT NO:14

X : PROGRAM CODE:
Q1. Execute the following code and write the output
CODE:
import java.io.*;
import java.net.*;
public class EX14Q1
{
public static void main(String args[])
{
try
{
InetAddress ip= InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e){System.out.println(e);}
}
}
OUTPUT:

XIII : EXERCISE:
Q1.Develop a program using InetAddress class to retrieve IP address of computer when hostname is
entered by the user.
CODE:
import java.util.*;
import java.net.*;
public class EX14Q2
{
public static void main(String args[])
{
String hname;
Scanner s = new Scanner(System.in);
System.out.println("Enter host name ");
hname=s.nextLine();
try
{
InetAddress a= InetAddress.getByName("localhost");
System.out.println("Host Name & IP Address: "+a.toString());
System.out.println("Host Name: "+a.getHostName());
EXPERIMENT NO:14

System.out.println("IP Address: "+a.getHostAddress());


}
catch(Exception e){System.out.println(e);}
}
}
OUTPUT:

You might also like