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

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




Infinite Loop, Can't find it?

 
Reply to this topicStart new topic

Infinite Loop, Can't find it?

Israel
9 Feb, 2007 - 07:00 AM
Post #1

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Why do I keep getting an infinite loop with this?

CODE
public class fibo {
    public static void main(String [] args) {
        int a=0, previous=1, sum=0;
        int x1=1;
        System.out.print(0+" ");
        System.out.print(1+" ");
        int i=0;
        while(i<8)
        {
            sum=a+previous;
            System.out.print(sum+" ");
            a=previous;
            previous=sum;
            i++;
        }
      
    }
}

User is offlineProfile CardPM
+Quote Post

1lacca
RE: Infinite Loop, Can't Find It?
9 Feb, 2007 - 07:04 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I don't.
User is offlineProfile CardPM
+Quote Post

Israel
RE: Infinite Loop, Can't Find It?
9 Feb, 2007 - 07:43 AM
Post #3

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Ahhh.... I'm just starting to learn Java but I'm finding that my most of my errors lie more in not understand the Borland compiler than the actual code. Even though I closed everything and closed the compiler when I opened it back up and re-entered that code, that works, I still got an infinite loop from my previous coding error. I wish I could just use JDK but my professor wants Borland. Thanks for checking that for me biggrin.gif
User is offlineProfile CardPM
+Quote Post

Israel
RE: Infinite Loop, Can't Find It?
9 Feb, 2007 - 10:22 AM
Post #4

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Ok... Now I'm not seeing any output? 1lacca, do you see any numbers when you run this script?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Infinite Loop, Can't Find It?
12 Feb, 2007 - 01:02 AM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I think I did, but since you use the print function, that does not flush the output, you might have to call System.out.flush(); or maybe System.out.println(); at the end.
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Infinite Loop, Can't Find It?
15 Feb, 2007 - 11:33 AM
Post #6

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 298



Thanked: 2 times
Dream Kudos: 50
My Contributions
I ran your code using BlueJ and it worked just fine sleepy.gif
User is offlineProfile CardPM
+Quote Post

codeninja
RE: Infinite Loop, Can't Find It?
16 Feb, 2007 - 07:51 AM
Post #7

New D.I.C Head
*

Joined: 16 Feb, 2007
Posts: 44


My Contributions
Bluejay is good for beginners I think.

http://www.bluej.org/


QUOTE(ajwsurfer @ 15 Feb, 2007 - 12:33 PM) *

I ran your code using BlueJ and it worked just fine sleepy.gif


User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Infinite Loop, Can't Find It?
16 Feb, 2007 - 07:55 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,350



Thanked: 51 times
Dream Kudos: 25
My Contributions
BlueJ is good for teaching the concepts of java to those who have not been exposed to it before..it allows them to understand how classes and objects work. It is also a good ide for users ofa ny level.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:11AM

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