Welcome to Dream.In.Code
Become a Java Expert!

Join 150,195 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,025 people online right now. Registration is fast and FREE... Join Now!




Assignment Called FunLoops :( Stuck

 
Reply to this topicStart new topic

Assignment Called FunLoops :( Stuck, Java and Magic Squares...

KennyWeather
15 Sep, 2008 - 01:04 PM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 1

The assignment says to write a method that prints the first n magic squares. So far I have this but when I run the program in BlueJ - it does what it's supposed to yet prints out an ArrayOUtofBounds exception...but still seems to run okay. Help? Thanks!


CODE
public class MagicSquare
{
    
    public MagicSquare()
    {
  
    }
    
    void magicNum(int n)
    {    
        // local variables
        int a = 0;
        double b;
        double c = 0;
        double e = 0;
        int count = 0;

        while (count < n)
        {
            a = a + 1;
            b = a * a;
            while ((c < b) && (c != b))
            {
                e++;
                c += e;
            }
            if (c == b)
            {
                count++;
                System.out.print(" " + b + ",");
            }
        }
    }
  
}

User is offlineProfile CardPM
+Quote Post

nick2price
RE: Assignment Called FunLoops :( Stuck
15 Sep, 2008 - 01:14 PM
Post #2

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
Wheres the rest of your code, the part that holds the Array? Seeing as this is whats throwing the error.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:32AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month