Scope of Variables in Java — issue

Okay so I’m having a problem with scope of an object. I’m using Jsoup right now and here’s the code:

//Website is /001.shtml, so adding count to the string wouldn't work.
//This is why I have the ifs

if (count < 10)
{
 Document site = Jsoup.connect(url + "00" + count).get();
}
else if (count < 100)
{
  Document site = Jsoup.connect(url + "0" + count + ".shtml").get();
}
else
{
  Document site = Jsoup.connect(url + count + ".shtml").get();
}

Okay so I create the Document object called
site, and I need to add a certain amount of zeros because of how the person made the website, no problem. However when I try to use site.select(anything), I can’t because the object was defined in the if construct.

Also, I can not initialize it outside the if, it does not work because I get a duplicate error thrown. Please tell me there is a fix for this because I have searched and searched to no avail, and I don’t want to have to put the rest of the program 3 times into different ifs…


Download scope.of.variables.in.java.issue.zip
Direct Link


Download


Download scope.of.variables.in.java.issue.zip
Mediafire


Download


Download scope.of.variables.in.java.issue.zip
Filedropper


Download

Both comments and pings are currently closed.

Comments are closed.