Need help with a magic square program
807603Jan 24 2008 — edited Jan 27 2008Hi, I have to write a code that prints out first 10 magic square numbers
-- magic square numbers: numbers that is a perfect square and sum of consecutive integers (like 36 -- 6 squared or sum of 1 to 8)
here's my code:
public class Loop {
public static void magicSquare ()
{
long inc = 0;
long integer = 0;
long total = 0;
for (int square =1; square>0; square++)
{
total = square*square;
int sum = 0;
for (int i = 1; i>0; i++)
{
if (sum<total){
sum += i;
}
else if (sum==total){
System.out.println("Magic Square is: " + total);
break;
}
else {
break;
}
}
}
}
}
I have a simple seperate driver