0

A method i have to write finds and prints "magic squares" which are numbers that are perfect squares and a sum of consecutive numbers (1+2+3,etc.)

Ex. the first 2 magic squares are 1 and 1225

it seems simple, but what i have doesn't work and i don't know y or where to go from here:

(long1 is initialized as 1, long2 = 1, sum = 0, divisor = 0, perfectSquare = false, numSquares is entered by the user in the main program and it is the number of perfect squares the user wants starting with 1)

```
public void magicSquare(int numSquares)
{
while(numSquares>0)
{
divisor = long1;
while(divisor>0)
{
if ((long1/divisor) == divisor)
perfectSquare = true;
divisor;
}
if (perfectSquare == true)
{
while(sum<long1)
{
sum+=long2;
long2+=1;
if (sum==long1)
{
System.out.println(long1);
numSquares-=1;
}
}
}
long1+=long1;
sum = 0;
perfectSquare = false;
long2 = 1;
}
}
```

If anyone could help me with this i would REALLY appreciate it

*Edited 3 Years Ago by happygeek*: fixed formatting