L
L
lidiya112019-07-03 15:59:33
Java
lidiya11, 2019-07-03 15:59:33

Why doesn't the intersects method work in a loop?

The bottom line is that there are 12 squares and you need to determine whether it intersects with at least one square from the brush list. For some reason, only the 12th, that is, the last square, is correctly determined. The rest is 0, that is, there is no intersection. What could be the problem?

public float[] checkKvadrat()
{
  float[] kvadr = new float[12];
  int q = 0;
  float y = 0;
  for (int i = 0; i < 12; i++) 
  {
    for (Rectangle br : brush) 
    {
      if(br.intersects(rectangle))
      {
        y = 1;
        break;
       }else y=0;
     }
   kvadr = y;
   y=0;
  }
return kvadr;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question