java - Magic Square program stuck in loop -


    public static void main(string[] args)     {         printmagic(1);     }     public static void printmagic(int n)     {         int count = 1;         int[] array = new int[n];         int magic = 0;         while(count<=n)         {             for(int = 0; <= count; i++)             {                 magic += i;                 if(math.sqrt(magic) == ((int)math.sqrt(magic)))                 {                  array[i] = magic;                  count++;                 }             }         }         for(int = 0; i<array.length; i++)         {            system.out.println(array[i]);         }     } 

this program supposed print n number of magic squares(a number has integer square root, , sum of consecutive numbers.) ex. square root of 36 6 , 1+2+3+4+5+6+7+8=36

i passing method number 3 in main function, getting stuck in loop(the candy cane looking bar in bluej)

is there im not seeing?

try this:

public static void printmagic(int n) {     int count = 0;     int[] array = new int[n];     int magic = 0;     for(int = 0; count < n; i++)     {         magic += i;         if(math.sqrt(magic) == ((int)math.sqrt(magic)))         {             array[count] = magic;             count++;         }     }     for(int = 0; i<array.length; i++)     {         system.out.println(array[i]);     } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -