Out: Tue 26 Feb 1998 Due: During Lab Session, or in 1 week
Programming Assignment:
Design and debug the Divisible.java program which prompts the user for three integers: a, b and upTo and prints out the number of integers from 1 to upTo which are:
Note: Use while loops - for loops will be talked about in a future class.
The modulus operator % is the best way to check for divisibility. An integer i is divisible by an integer j if:
if ( ( i%j ) == 0 ) { // j divides i }That is, the remainder when i is divided by j is zero. If either i or j are negative, the result has the sign of the i.
5%3 produces 2 5%(-3) produces 2 (-5)%3 produces -2 (-5)%(-3) produces -2It is done this way so that
((i/j)*j + (i%j)) == iis always true. (Integer division rounds towards zero.)
Use PostIt to submit your homework. There are further instructions about how to do this.