paintComponent is executing twice

后端 未结 2 1792
感动是毒
感动是毒 2020-12-21 11:59

This is bothering me, my code works and runs but when I went to run it, it seems to be looping my for loops twice, can anyone help me with my logic? Thanks...



        
2条回答
  •  渐次进展
    2020-12-21 12:46

           for(int i = 0; i < radius.length; i++)
           {
               for (int j = 0; j < radius.length; j++)
               {
    

    Most loops where you wish to compare every pairing of two elements together is instead written like this:

           for(int i = 0; i < radius.length; i++)
           {
               for (int j = i; j < radius.length; j++)
               {
    

    (Note the j = i in the second loop.)

    This also lets you remove the i != j test. :)

    EDIT: Oops; j = i means you still need to i != j test -- if you used j = i+1 then you can remove the i != j test. Sigh. :)

提交回复
热议问题