If statement not returning anything
Code Java:
import java.net.*;
import java.io.*;
public class Foo{
public static void main (String[] args)
{
try {
InetAddress thisIp = InetAddress.getLocalHost();
String[] result = thisIp.getHostAddress().split("[.]");
String IPAddr = (result[0] + "." + result[1] + "." + result[2]);
for (int i = 1; i < 256; i ++)
{
//For loop
String IPAddress = (IPAddr + "." + i);
System.out.println(IPAddress);
if (IPAddress == (result[0] + "." + result[1] + "." + result[2] + "." + result[3]))
{
System.out.println("IP FOUND");
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm not sure why this isn't working, the IF statement doesn't return anything to the console.
Any ideas?
Thanks a bunch!
Re: If statement not returning anything
1.) It only prints, not returns anything.
2.) Even if it did, main is void so it can't return anything.
3.) For a String, use the .equals method.
Re: If statement not returning anything
try
if (IPAddress.equals(......))
Re: If statement not returning anything
Thanks
That worked perfectly!