package com.company;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.*;
public class Main {
public static void main ( String [] args ) throws UnknownHostException
{
//Finding Ip
InetAddress address = InetAddress.getLocalHost();
String hostIP = address.getHostAddress() ;
String hostName = address.getHostName();
//Finding Free Port
int startPortRange=0;
int stopPortRange=65365;
for(int i=startPortRange; i <=stopPortRange; i++)
{
try
{
Socket ServerSok = new Socket(hostIP,i);
System.out.println("Port in use: " + i );
ServerSok.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Port not in use: " + i );
}
}
When I run the code it says that variable "i" is not found. How should I fix this? I had this issue with the ip Finding section and someone helped me fix it with putting throw next to static void but I don't know how to do it with this one.