Skip to content

Instantly share code, notes, and snippets.

@speters33w
Created September 19, 2022 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speters33w/75135dc0c837c5e822c6c434b1b7204a to your computer and use it in GitHub Desktop.
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
/*
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