Created
September 19, 2022 02:12
-
-
Save speters33w/75135dc0c837c5e822c6c434b1b7204a to your computer and use it in GitHub Desktop.
My answer to mooc.fi java Programming exercise 2_26: Divisible by three
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Write a method public static void divisibleByThreeInRange(int beginning, int end) | |
that prints all the numbers divisible by three in the given range. | |
The numbers are to be printed in order from the smallest to the greatest. | |
public static void main(String[] args) { | |
divisibleByThreeInRange(3, 6); | |
} | |
Sample output | |
3 | |
6 | |
public static void main(String[] args) { | |
divisibleByThreeInRange(2, 10); | |
} | |
Sample output | |
3 | |
6 | |
9 | |
*/ | |
public class DivisibleByThree { | |
public static void divisibleByThreeInRange(int beginning, int end){ | |
while(beginning <= end){ | |
if(beginning % 3 == 0){ | |
System.out.println(beginning); | |
} else { | |
beginning++; | |
continue; | |
} | |
beginning += 3; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment