Okay, so I am taking an intro class for java programming and my instructions for this program were to write a program that found the first 20 numbers that when divided by 2,3,4,5,6 all left a reminder of one and then when divided by 7, left a reminder of 0. The first number of the 20 is 301. Now I have to write a program that finds the next 19.

I believe I have the solution, but I know there is something keeping my while loop from running. Any insight would be phenonmenal! I have been staring at this for a few days now and I cannot seem to put my finger on while the while loop will not do anything.

Thank you very much!!

import java.io.*;

public class third_program 

{public static void main(String[] args) throws IOException
	{
	
int numberSuccess=0	
int number=0;	
		
System.out.println ("This program is going to find the first 20 numbers which, when divided by 2,3,4,5,6 leave a remainder of 1and evenly divide by 7. ");
System.out.println ();
		
while (numberSuccess < 20 ); 		

{
number=0;

if (number%2==1 && number%3==1 && number%4==1 && number%5==1 && number%6==1 && number%7==0)
					
	{System.out.print(number);
	numberSuccess++; number++;}

else number++;
			    
   }
		
System.out.print("The successful numbers are " +number);
		
	}

}

If in the while loop leave out the initialisation of number=0; it should work, now you are always testing zero.

Thank you very much for responding!

I tried removing the number=0 from the while loop, and it still failed to print anything from the while loop.

It does not print anything except the header:

"This program is going to find..."

Have you recompiled?

I'm sorry, ddanbe, but I am not sure what you mean when you say recompile...

Again, I really appreciate you taking time to help me out here. I am growing really frustrated with this because it seems like I have everything in working order and I am not sure why it is not printing.

I also noticed you have not included a Read line, char, key, or something at the end. So it might be that all is happening but as soon as it does it disappears...

which number = 0 did you take out? you need to take out? You have two of them, and one of them doesn't even end the line with a semi-colon

ddanbe - who knows what IDE he is using if any - but doesn't eclipse do that for him automatically when he hits run or runas

import java.io.*;

public class testSound 

{public static void main(String[] args) throws IOException
	{
	
int numberSuccess=0	;
int number=0;	
		
System.out.println ("This program is going to find the first 20 numbers which, when divided by 2,3,4,5,6 leave a remainder of 1and evenly divide by 7. ");
System.out.println ();
		
while (numberSuccess < 20 )		

{


if (number%2==1 && number%3==1 && number%4==1 && number%5==1 && number%6==1 && number%7==0)
					
	{System.out.print("match found "+number);
	numberSuccess++; number++;}

else number++;
			    
   }
		
System.out.print("The successful numbers are " +number);
		
	}

}

I think this is wat ur expecting

please use code tags to make readibility easier

If you add a multiple of 420 to 301 you get the next number.
So 7*420+301=3241 is a number that applies.

I really appreciate all of the help guys!!!

The error I was running into was the semi-colon after the while... it was not allowing the while to even begin.

Thank you again!!

If you add a multiple of 420 to 301 you get the next number.
So 7*420+301=3241 is a number that applies.

Wow, how did you figure that out?

don't be fooled by that picture - ddanbe is an 11 yr old child prodigy

I really appreciate all of the help guys!!!

The error I was running into was the semi-colon after the while... it was not allowing the while to even begin.

Thank you again!!

i have removed it in the code i sent u ...

by the way - that comment about ddanbe was a joke, I don't know him but hope he has a good sense of humor.

Wow, how did you figure that out?

Just by looking at the output when I run your program and noticing that every number in the series was 420 higher then the previous one.

rapture : I am a 99 year old thootless, bearded bag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.