Results 1 to 3 of 3
  1. #1
    bzupnick is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Default unexplainable problem

    i just started doing project euler (projecteuler.net) and i hit a really weird problem in my code
    PHP Code:
    class euler1{	
    public static void main(String[]args) {
    
    int numb = 1;
    
    while (numb > 999) {
    
    int mod3 = numb % 3;
    int mod5 = numb % 5;
    
    	if (mod3 > 1)
    		System.out.println(numb); 
    	if (mod5 > 1)
    		System.out.println(numb); 
    	numb++;
    		}
    	}
    }
    it compiles correctly but when i run it it doesnt print anything, all the help i can get is greatly appreciated

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    you loop is saying while(1 > 999) which is false so it leaves the loops before it starts

    it should be:

    Java Code:
    while(numb<999)
    Or you could go with a for loop:

    Java Code:
    for(int numb=1; numb < 999; numb++)
    {
       ...
    }
    My Hobby Project: LegacyClone

  3. #3
    bzupnick is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •