java - Variable might have not been initialized? -


here java code (a terrible brute force algorithm know , that's requirement). think have initialized j variable in loop before references, when run compiler alerts.

import java.util.arrays;  public class brute {      public static void main(string[] args) {          string filename = "./collinear/input" + args[0] + ".txt";         in f = new in(filename);         int n = f.readint();         point[] points = new point[n];         int x, y;          stddraw.setscale(-10000, 50000);          for(int = 0; < n; i++) {             x = f.readint();             y = f.readint();             points[i] = new point(x, y);             points[i].draw();         }          arrays.sort(points);           int i, j, k, l;          for(i = 0; < n; i++)             for(j = 0; j < n; j++)                 if(points[j] == points[i]) continue;                 for(k = 0; k < n; k++)                     if((points[k] == points[i]) || (points[k] == points[j])) continue;                     for(l = 0; l < n; l++) {                         if((points[l] == points[i]) || (points[l] == points[j])                             || (points[l] == points[k])) continue;                         if(points[i].slopeto(points[j]) == points[i].slopeto(points[k])                         && points[i].slopeto(points[k]) == points[i].slopeto(points[l])) {                             stdout.println(points[i].tostring()                              + " -> " + points[j].tostring()                              + " -> " + points[k].tostring()                              + " -> " + points[l].tostring());                              points[i].drawto(points[l]);                         }                     }             } } 

brute.java:31: error: variable j might not have been initialized

if((points[k] == points[i]) || (points[k] == points[j])) continue;

brute.java:33: error: variable j might not have been initialized

if((points[l] == points[i]) || (points[l] == points[j])

put braces around body of loops.

this:

for(j = 0; j < n; j++)     if(points[j] == points[i]) continue;     for(k = 0; k < n; k++) ..... 

is loop of 1 line doesn't anything, followed loop.

you mean this:

for(j = 0; j < n; j++) {     if(points[j] == points[i]) continue;     for(k = 0; k < n; k++) {         .....     } } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -