Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with Homework

843789Jun 19 2009 — edited Jun 19 2009
I need to use a 'for', 'while', or 'do-while' loop to determine all of the numbers that evenly divide into numbers entered by the user. Here are the steps.

1) Ask the user for 3 numbers. A start number, end number, and divisor.
2) Using one of the loops mentioned above, list all of the numbers between the start and end numbers that are eveningly divisable by the divisor.
3) The output should look like this: The following numbers
between start and end
are divisible by divisor
number
number
etc

Here is what I have so far. Basically I have no idea with the loop. I know I can use the % mod and see which numbers have a remainder of 0 so I need something like
if ( inStart % inDivisor == 0 ) Please help me!!
import javax.swing.*; // needed for JOptionPane

class Loop
{
	public static void main(String args [])
	{
		String start = JOptionPane.showInputDialog("Enter a start number:");
		String end = JOptionPane.showInputDialog("Enter an end number:");
		String divisor = JOptionPane.showInputDialog("Enter a divisor:");

		int inStart = Integer.parseInt(start); // converts the string to an integer
		int inEnd = Integer.parseInt(end);
		int inDivisor = Integer.parseInt(divisor);

                                int x = ( inStart % inDivisor )
      	                for (int count = (inStart); count < inEnd; count++)
                                     {
                                      System.out.println(factorial *= count);
                                     }

	} // end main

} // end class ConvertTemp04
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2009
Added on Jun 19 2009
6 comments
591 views